Automattic / Automattic/newspack-migration-tools
Blocks Generator Enhancements: Paragraph
- Dominant language
- PHP
- Stars
- 20
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
## The Issue(s)
The `get_paragraph()` method of the `GutenbergBlockGenerator` class needs several updates to match all supported features of the Paragraph Block.
The [current](https://github.com/Automattic/newspack-migration-tools/blob/1d8ce878adeb414be4ae4f0017cb46a97dd86945/src/Logic/GutenbergBlockGenerator.php#L469) implementation has 5 available parameters:
* `string` $paragraph_content
* `string` $anchor
* `string` $text_color
* `string` $font_size
* `array` $additional_css_classes
The attributes below cannot be added currently in any way:
1) `NEW` text align support
2) `BUG` text color support. [Currently existing](https://github.com/Automattic/newspack-migration-tools/blob/1d8ce878adeb414be4ae4f0017cb46a97dd86945/src/Logic/GutenbergBlockGenerator.php#L476C12-L476C20), but with a wrong array key, therefore not applied
3) `NEW` custom attributes
3.1) Drop Cap support
3.2) Direction (LTR | RTL) support
3.3) Letter Spacing
3.4) Dimensions (padding/margin)
3.5) Letter Case
3.6) Decoration
3.7) Letter Spacing
3.8) Appearance (aka Font Weight)
## The Proposal
Personally, I think we don't need to explicitly define every available attribute as a method parameter. Instead, we can have an optional `array` parameter `$attributes` to define everything we need. Then, in the method definition, we can check whether a specific attribute is specified and apply the necessary changes to class names.
The current `$anchor`, `$text_color`, and `$font_size` parameters can be deprecated, but will still be supported for a short period.
## The Implementation
I) In order not to break anything currently using the method, we can just define `$attributes` as the 6th parameter, like so:
```
public function get_paragraph( $paragraph_content, $anchor = '', $text_color = '', $font_size = '', array $additional_css_classes = [], array $attributes = [] ) {
// And in order to force the usage of this new parameter, to deprecate `$anchor`, `$text_color` and `$font_size`
if ( ! empty( $anchor ) ) {
_deprecated_argument( __FUNCTION__, '2.0', '$anchor should be set in the $attributes parameter' );
$attributes['anchor'] = $anchor;
}
}
```
II) At some point, we can remove the deprecated parameters and leave the method definition as followed:
```
public function get_paragraph( $content, array $attributes = [], array $additional_css_classes = [] ) {
// ...
}
```
👉 **Such issues exist with most block generation methods, and once we agree on a method definition, I can open new issues for the rest.**
@Automattic/newspack-launch-and-infrastructure Can I get your thoughts on this matter? Thanks 🙏
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.