Problem/Motivation

Experiment with adding deprecated and replace_by style support for styles.

Proposed resolution

Add two new properties in style definition:

old-style:
  title: 'I am old and need of replacement'
  description: ''
  groups:
    - teaser
  deprecated: false
  replaced_by: new-style

Property `deprecated` will add '(Deprecated)' in the UI and also not allow this style to be attached to new paragraphs.

Property `replaced_by` will replace this style with a replaced by style in the rendering. This means that paragraphs that are using replaced styles will use now styles for replaced by style (CSS classes, template suggestions, etc).

Remaining tasks

- Discuss
- Test on real projects
- Figure if this is really needed

User interface changes

- Deprecated styles will not be selectable any more for new paragraphs.
- Deprecated styles will have additional text '(Deprecated)' in style name.

API changes

Two new properties are added to styles yaml definitions.

Method ParagraphsStylePlugin::getStyles() is getting a new $replaced_by boolean attribute:

public function getStyles(ParagraphInterface $paragraph, bool $replaced_by = TRUE) {}

Data model changes

None.

Comments

pivica created an issue. See original summary.

pivica’s picture

Status: Active » Needs review
StatusFileSize
new3.12 KB

Here is a first patch.

If we decide that this is useful we will need to add some test coverage also.

Status: Needs review » Needs work

The last submitted patch, 2: 3394637-style-deprecated-replaced-by-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

pivica’s picture

Status: Needs work » Needs review
StatusFileSize
new2.27 KB
new4.18 KB

Found a bug when editing a paragraph that has a style which is replaced now in select box you would get replaced by style instead of manually selecting some other style. This patch is fixing this.

No idea about failed tests, they don't look related to this.

pivica’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 4: 3394637-style-deprecated-replaced-by-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

The test fails are a PHP version issue, looks like blazy broke compatibility with PHP 7.3 and we'll need to update that.

+++ b/src/Plugin/paragraphs/Behavior/ParagraphsStylePlugin.php
@@ -363,19 +373,31 @@ class ParagraphsStylePlugin extends ParagraphsBehaviorBase implements ContainerF
+          // If style is replaced_by and replaced_by style exist and is enabled
+          // then replace it by new style.
+          if ($replaced_by && !empty($style_config['replaced_by'])) {
+            $enabled_styles = \Drupal::config('paragraphs_collection.settings')->get('enabled_styles');
+            if (in_array($style_config['replaced_by'], $enabled_styles) && $replaced_style = $this->yamlStyleDiscovery->getStyle($style_config['replaced_by'])) {
+              $style = $replaced_style['name'];

yamlStyleDiscovery->getStyle() already verifies that it is enabled, you don't need to duplicate that.

pivica’s picture

Status: Needs work » Needs review
StatusFileSize
new4.02 KB
new1.01 KB

Thx here is updated patch with changes suggested in 7.

Status: Needs review » Needs work

The last submitted patch, 8: 3394637-style-deprecated-replaced-by-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

berdir’s picture

Notes on implementing a test for this:

create a deprecated and replaced_by style definition
create a paragraph with that style and put it in a node through the API. You can find examples doing that in _paragraphs_collection_demo_create_demo_article()
visit that node, verify the specified replacement style is used
edit the node, verify the deprecated style is shown, change it, save, edit again, verify it doesn't show up anymore.