Problem/Motivation

From #2628168-2: Clean up Entity Embed's data model:

Also note that data-entity-embed-settings contains the settings specific to the selected display (data-entity-embed-display), therefore this is actually currently misnamed: data-entity-embed-display-settings would make much more sense.

Proposed resolution

Rename data-entity-embed-settings attribute to data-entity-embed-display-settings. Make sure BC layer is implemented:

- Entity embed filter should work with both
- Entity embed button should recognize both but only save new attribute

We should test BC layer where possible (text filter).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

slashrsm created an issue. See original summary.

slashrsm’s picture

thenchev’s picture

Assigned: Unassigned » thenchev
Status: Active » Needs review
FileSize
24.25 KB

So renamed all occurrences of data-entity-embed-display added test to se if it still works with the old attribute.

Tested it manually with -
display as label that is linked. The entity is shown with both new and old attributes and the button seems to recognize the old attribute and changes it to the new on save.

Looks like it works for me but would like a second opinion.
Do we need more test coverage?

slashrsm’s picture

Status: Needs review » Needs work
  • +++ b/src/Tests/EntityEmbedFilterTest.php
    @@ -177,6 +177,21 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    // data-entity-embed-settings is
    +    // replaced with data-entity-embed-display-settings. Check to see if
    +    // data-entity-embed-settings is still working.
    

    Fix wrapping.

  • BC-compatibility is not working. You must have been testing with the default configuration values. Here is how I tested it: embed node with "Label" plugin, disable link, embedded node display correctly, apply patch, rebuild caches, reload and see how embedded node is now displayed with a label that is a link, edit, edit embedded node, see link being enabled since old settings were not parsed correctly.
  • We will also need to update text formats. If there is a HTML filter enabled on the same format as the embed button we need to add the new attribute to the list of allowed attributes. We would also need to test that.
Dave Reid’s picture

I'm going to push back on this one. Yes it contains display settings, but I also envisioned it being used to store additional things like "Override the node title or field X value when embedded here", which isn't necessarily related to display, but rather the embed itself. I think this changes the data structure unnecessarily. This change mostly seems to be about semantics, so unless there is a more compelling argument, I think this should be won't fixed in a week.

slashrsm’s picture

I thought that we agreed in the past that having data structures where we throw anything that comes to mind isn't the way to go. Having responsibilities clearly separated has been a guideline for a while and is also a general best practice.

Could a tool that allows overriding of certain fields/data use its own attribute? Is there an issue for that where we could discuss the architecture? Has any development work been done with regards to that? It is impossible to plan further development and roadmap if we do not communicate ideas through standard channels.

Semantics and clear data model are compelling enough for something like this. Specially this close to beta as we are at the moment. Clear standards improve DX and encourage people to use the tools we provided in a way they were meant to be used.

thenchev’s picture

Status: Needs work » Needs review
FileSize
7.37 KB
30.89 KB

Some updates. Still looking into tests. There will be test fails.

Status: Needs review » Needs work

The last submitted patch, 7: rename-2760801-7.patch, failed testing.

slashrsm’s picture

  1. +++ b/src/Plugin/Filter/EntityEmbedFilter.php
    @@ -104,6 +106,13 @@ class EntityEmbedFilter extends FilterBase implements ContainerFactoryPluginInte
    +        // data-entity-embed-settings is deprecated, make sure we convert it to
    +        // data-entity-embed-display-settings.
    +        if ($settings = $node->getAttribute('data-entity-embed-settings')) {
    +          $node->setAttribute('data-entity-embed-display-settings', $settings);
    +          $node->removeAttribute('data-entity-embed-settings');
    +        }
    +
    

    Let's check and do this only if the data-entity-embed-display-settings does not exist.

  2. +++ b/src/Tests/EntityEmbedFilterTest.php
    @@ -177,6 +177,21 @@ class EntityEmbedFilterTest extends EntityEmbedTestBase {
    +    // data-entity-embed-settings is
    +    // replaced with data-entity-embed-display-settings. Check to see if
    +    // data-entity-embed-settings is still working.
    +    $content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid() . '" data-entity-embed-display="default" data-entity-embed-settings=\'{"view_mode":"full"}\' data-align="left" data-caption="test caption">This placeholder should not be rendered.</drupal-entity>';
    

    Comment wrapping.

    I'd also make sure non-default display settings are used (full view mode will be used by default AFAIK). Only in that case we prove that they are really respected.

  3. +++ b/src/Tests/EntityEmbedUpdateHookTest.php
    @@ -40,4 +41,24 @@ class EntityEmbedUpdateHookTest extends UpdatePathTestBase {
    +        'allowed_html' => 'data-entity-embed-settings',
    

    Let's add full drupal-entity tag instead just one argument. For the paranoia sake...

  4. +++ b/tests/fixtures/update/entity_embed.update-hook-test.php
    @@ -23,6 +48,7 @@ $extensions = $connection->select('config')
    +$extensions['module']['embed'] = 8000;
    

    Do we need to rely on this?

  5. +++ b/src/Plugin/Filter/EntityEmbedFilter.php
    @@ -104,6 +106,13 @@ class EntityEmbedFilter extends FilterBase implements ContainerFactoryPluginInte
    +        // data-entity-embed-settings is deprecated, make sure we convert it to
    +        // data-entity-embed-display-settings.
    +        if ($settings = $node->getAttribute('data-entity-embed-settings')) {
    ...
    +          $node->removeAttribute('data-entity-embed-settings');
    +        }
    

    Let's check and do this only if data-entity-embed-display-settings doesn't exist.

  6. +++ b/js/plugins/drupalentity/plugin.js
    @@ -82,8 +82,8 @@
    -        allowedContent: 'drupal-entity[data-entity-type,data-entity-uuid,data-entity-embed-display,data-entity-embed-settings,data-align,data-caption]',
    
    +++ b/src/Form/EntityEmbedDialog.php
    @@ -154,12 +154,12 @@ class EntityEmbedDialog extends FormBase {
    -      'data-entity-embed-settings' => array(),
    -    );
    +      'data-entity-embed-display-settings' => isset($form_state->get('entity_element')['data-entity-embed-settings']) ?: [],
    +    ];
    

    Doesn't work correctly. Sets 'data-entity-embed-display-settings' to boolean instead of array of configuration in case of the old attribute name. (isset()...)

thenchev’s picture

Status: Needs work » Needs review
FileSize
6.39 KB
31.22 KB

About #4 when i remove it i get:
Drupal\Component\Plugin\Exception\PluginNotFoundException: The "embed_button" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 125 of /var/www/html/d8/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

The thing is, what i think, because we need Embed to be installed when i run the tests i get errors. The database is used for the test with the standard drupal installation.

Status: Needs review » Needs work

The last submitted patch, 10: rename-2760801-10.patch, failed testing.

slashrsm’s picture

Status: Needs work » Needs review
FileSize
830 bytes
31.6 KB

This should fix the failing test.

slashrsm’s picture

Tested this manually and I can confirm that backward compatibility works as expected.

I will tentatively RTBC this due to questions that were raised. Let's try to resolve any difference in views but let's try to do it in a timely manner. Specially due to the beta blocker status of this issue.

slashrsm’s picture

Status: Needs review » Reviewed & tested by the community
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

  • slashrsm committed 72a93e2 on 8.x-1.x authored by Denchev
    Issue #2760801 by Denchev, slashrsm: Rename data-entity-embed-settings...
Dave Reid’s picture

Due to 'data-entity-embed-settings' being removed from the CKEditor 'allowedContent' and 'requiredContent' settings, does that mean existing embeds will no longer be upcasted to widgets?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.