Convert twitter, video and image paragraphs.
Merge request reports
Activity
79 79 */ 80 80 public function build(FieldItemListInterface $items, CustomElement $custom_element, $langcode = NULL) { 81 81 if ($items instanceof EntityReferenceFieldItemListInterface) { 82 $nested_elements = []; 83 foreach ($items->referencedEntities() as $entity) { 84 $nested_elements[] = $this->ceGenerator->generate($entity, $this->configuration['mode'], $langcode); 85 } 86 if ($this->isSlot()) { 87 $custom_element->setSlotFromNestedElements($this->getName(), $nested_elements); changed this line in version 4 of the diff
https://www.drupal.org/project/custom_elements/issues/3447937 == !68 (merged) .
I'm rebasing this MR on that one, so will likely need to rebase again when that is done.
1 <?php 2 3 namespace Drupal\custom_elements\Plugin\CustomElementsFieldFormatter; 4 5 use Drupal\Core\Field\FieldDefinitionInterface; 6 use Drupal\Core\Field\FieldItemListInterface; 7 use Drupal\Core\Form\FormStateInterface; 8 use Drupal\custom_elements\CustomElement; 9 use Drupal\custom_elements\CustomElementsFieldFormatterBase; 10 use Symfony\Component\DependencyInjection\ContainerInterface; 11 12 /** 13 * Implementation of the 'video_embed' custom element formatter plugin. 14 * 15 * Sets embed URL and thumbnail from the applicable video provider. @roderik is there no core formatter doing something similar? but if not, yeah, that seems reasonable
- There are only core formatters for "Video" and "thumbnail" -- i.e. one of both properties, not both of them.
- The "Video" also doesn't output just the video embed URL (there seems to be nothing for that in Core), but a div with an iframe that has the video embed URL as 'src' -- didn't seem ideal to me.
<pg-video type="video" view-mode="full" media-video-embed-field="<div class="video-embed-field-provider-youtube video-embed-field-responsive-video"><iframe width="854" height="480" frameborder="0" allowfullscreen="allowfullscreen" src="https://www.youtube.com/embed/IPR36uraNwc?autoplay=1&amp;start=0&amp;rel=0"></iframe></div>"></pg-video>
1 uuid: ef603016-2b8e-4ffe-a201-fb0f38b7b748 This + below config-export files: added without much investigation.
There are two fields on the 'image' media entity called "Image": field_image (used by us) and field_media_image (not used).
I don't know why. field_media_image is not mentioned in the export for core.entity_view_display.media.image.default - even though it's visible on the "Edit display" screen. (Maybe only because I didn't re-save that screen?)
Now our new exported ce_display does mention it as a dependency, so it needs to also be exported.
You're right. This is a mistake of me adding the CE configs to this module. I should move them into the thunder submodule.
However, I keep getting errors in the functional test at the moment. Can I wait with this until after I convert the gallery / can we temporarily commit these extra config files now?
I've added subtask https://www.drupal.org/project/custom_elements/issues/3449313, to do immediately after the 'gallery paragraph' conversion is done.
151 151 return preg_replace("/> +</", "><", $string); 152 152 } 153 153 154 /** 155 * Tests paragraphs. 156 */ 157 public function testParagraphs() { 158 // We test all paragraph types from a single test method so the setup() 159 // routine is only run once for all of them - saves time. 160 $this->doTestTwitterParagraph(); 161 $this->doTestVideoParagraph(); 162 $this->doTestImageParagraph(); 163 $this->doTestGalleryParagraph(); changed this line in version 2 of the diff
added 1 commit
- 4168d3f3 - Fix eslint + reinstate gallery tests (not yet converted).
1 <?php 2 3 namespace Drupal\custom_elements_thunder\Processor; Requesting to postpone for a day (and already commit this), per !65 (comment 315074)
1 uuid: dadd4eca-7032-44fa-9d3a-18f605a44231 2 langcode: en-gb For completeness: yes, we will continue testing on exported config (instead of config generated in the test) specifically for these thunder-paragraph related tests only. Because we should have 'importable' config, for the benefit of users, and that is what we're (also) testing.
Other tests will have config generated in the test.
79 79 */ 80 80 public function build(FieldItemListInterface $items, CustomElement $custom_element, $langcode = NULL) { 81 81 if ($items instanceof EntityReferenceFieldItemListInterface) { 82 $nested_elements = []; 83 foreach ($items->referencedEntities() as $entity) { 84 $nested_elements[] = $this->ceGenerator->generate($entity, $this->configuration['mode'], $langcode); 85 } 86 if ($this->isSlot()) { 87 $custom_element->setSlotFromNestedElements($this->getName(), $nested_elements); 82 $entities = $items->referencedEntities(); 83 // Ignore 'flatten' for multi-value fields. 84 if (empty($this->configuration['settings']['flatten']) I fail to follow the logic from this formatter when reading the resulting code now. I don't see where all cases are handled. If not flattening, I don't see where all the attribute logic is done.
IT'S not logical to me that flatten totally changes how this works. Could it do its work and apply flatten in the end?
changed this line in version 4 of the diff
OK, I've merged the 'if' and 'else' now, so that the same logic path is followed.
Things are parsed through a normalizer now. There are some differences:
- Separate "type" and "COMPONENTNAME-type" properties are added, which is great.
- All properties are now prefixed with "COMPONENTNAME-", instead of added as-is, which is great/fine.
- It turns out that the normalizer converts hyphenated "component-name" to "componentName" which is now inconsistent with how our formatters treat 'field prefixes'. I don't know the exact reason / preferred naming scheme.
Question:
Anywhere where our formatters use their configured name as a prefix to add multiple attributes (like FlattenedCeFieldFormatter does), should we camelCase things instead? Like "prefixProperty" instead of "prefix-property"?
See EntityReferenceCeFieldFormatterTest.php line 231 and ParagraphFormatterTest.php line 222/twitter for examples. (I never know if these direct links work...)
added 9 commits
-
a17185c5 - 1 commit from branch
project:3.x
- 20f32b6d - Tests for entityreference formatter.
- 51566e99 - phpcs
- 2d2f8ee4 - Convert twitter, video and image paragraphs.
- 071b592c - Fix eslint + reinstate gallery tests (not yet converted).
- abdf27ce - Fix botched cherry-pick.
- ff9ab2fb - 'Flattened' tests working.
- 4dd08dc0 - Unify behavior of flatten+multivalue with Flattened formatter.
- 928f24be - Change 'flattened' logic in entityreference formatter; adjust tests to go along with it.
Toggle commit list-
a17185c5 - 1 commit from branch
Did a push and answered some comments. "Actual code changes" should be done but I'm still moving exported files to their newer location.
Edited by Roderik Muitadded 8 commits
-
c9fda6d5 - 1 commit from branch
project:3.x
- 5f14b50c - Convert twitter, video and image paragraphs.
- 30b8996c - Fix eslint + reinstate gallery tests (not yet converted).
- 747c65b1 - Fix botched cherry-pick.
- 6e05cc45 - 'Flattened' tests working.
- 042da4db - Unify behavior of flatten+multivalue with Flattened formatter.
- 0540b1d5 - Change 'flattened' logic in entityreference formatter; adjust tests to go along with it.
- fa84e80f - Rename kernel tests and add comment that they are dependent on imported config.
Toggle commit list-
c9fda6d5 - 1 commit from branch
83 foreach ($items->referencedEntities() as $entity) { 89 foreach ($entities as $entity) { 84 90 $nested_elements[] = $this->ceGenerator->generate($entity, $this->configuration['mode'], $langcode); 85 91 } 86 if ($this->isSlot()) { 92 93 if ($this->isSlot() && empty($this->configuration['flatten'])) { 87 94 $custom_element->setSlotFromNestedElements($this->getName(), $nested_elements); 88 95 } 89 96 else { 90 97 $normalizer = new CustomElementNormalizer(); 91 98 $context = ['cache_metadata' => new BubbleableMetadata()]; 92 if ($this->getFieldDefinition()->getFieldStorageDefinition()->getCardinality() == 1) { 99 if ($this->getFieldDefinition()->getFieldStorageDefinition()->getCardinality() == 1 100 || !empty($this->configuration['flatten'])) { 93 101 $value = $normalizer->normalize($nested_elements[0], NULL, $context); added 1 commit
- 4c3216fb - Suppress camelCasing keys in the normalized array used in EntityReferenceCeFieldFormatter.