For now the preprocessor only supports scalar fields, so more complex fields of paragraphs are still rendered as usual.

This patch adds support for the default thunder paragraphs.

Comments

arthur_lorenz created an issue. See original summary.

fago’s picture

Status: Needs review » Needs work

- This needs to check it's working with node articles first.

+ case 'field_text':
+ $entity_values->setDataAttribute($field_name, json_encode($entity->{$field_name}->value));

this doe snot make sense to me. it should either just use the plain value without json encding or the ->processed field if markup is there

+ case 'pinterest':
+ $entity_values->setDataAttribute('pinterest_url', $media_entity->field_url->uri);
+ break;

Let's just stay with an uri attribute. Why would we generate a pinterest element with a pinterest_url attribute? The logical name would be URL.

This shows we really need to to do #2994914: Allow modules to control how entity fields are transformed. But let's handle this there and re-factor this later.

arthur_lorenz’s picture

Status: Needs work » Needs review
StatusFileSize
new6.58 KB

Added new patch

  • 'field_text' will now be rendered in backend and included via slot
  • Renamed `pinterest_url` property to `url`
fago’s picture

Status: Needs review » Needs work

>Let's just stay with an uri attribute. Why would we generate a pinterest element with a pinterest_url attribute? The logical name would be URL.

Pinterest was just the example, same for others:

+ case 'twitter':
+ $entity_values->setDataAttribute('twitter_url', $media_entity->field_url->uri);
+ break;

How about instagram, isn't that included?

arthur_lorenz’s picture

Status: Needs work » Needs review
StatusFileSize
new6.56 KB

>Pinterest was just the example, same for others:
makes sense, fixed for twitter and instagram aswell

>How about instagram, isn't that included?
sure, it was included from the beginning ;)

fago’s picture

StatusFileSize
new6.58 KB

I figured that this uses related URLs for image media, but it should be absolute so that the custom element markup is re-usable. Attaching a new patch.

Still we need to address #2994914: Allow modules to control how entity fields are transformed for being able to implement this properly.

arthur_lorenz’s picture

StatusFileSize
new6.6 KB

Same issue for URLs in gallery images. New patch attached.

fago’s picture

#2994914: Allow modules to control how entity fields are transformed is fixed in 2.x now. It has this code refacored as ThunderParagraphsCustomElementsProcessor - however that's a WIP and needs to be completely refactored still.

Todos to make this work properly:
- For each media bundle in thunder, add a MediaEntity{ bundle}Processor. The processor should support media entities and control how they are rendered.
- Since we know it's thunder we can assume the thunder fields and add an optimized custom element tag for the media entity.
- In the end, we should have a wrapping custom element tag per paragraph that contains slot elements as suiting.

pagach’s picture

Patch with default processor for thunder gallery.
Wrong file. Correct file in comment #11

pagach’s picture

pagach’s picture

Patch with default processor for thunder gallery.

pagach’s picture

New patch with --staged diff for added files.

fago’s picture

Status: Needs review » Needs work
+  public function addtoElement($data, CustomElement $element, $viewMode) {
+    assert($data instanceof MediaInterface);
+    $paragraph = $data;

since it's working for paragraphs, $data must be the paragraph entity and the assert wrong?

* Default processor for media field items.
+ */
+class MediaEntityGalleryProcessor implements CustomElementProcessorInterface {
+
+ use CustomElementGeneratorTrait;
+

This says it's handling media entities, but then it handles the paragraph type 'gallery'. Mismatch.

+ use CustomElementGeneratorTrait;
not used?

Why has the gallery a separate class and the other paragraphs not?
I think it would be cleanest to have a single class per paragraph type / media entity bundle so it can be easily extended like that and it's easy to overrride the output for a single paragraph only.

pagach’s picture

Here is a patch with all thunder paragraphs in separate class.
Also removed unused trait (it is not used since nested element "lupus-" tag and not a custom_elements tag).
Refactored to use Paragraph instead of MediaEntity.

  • fago committed aa09d10 on 8.x-2.x authored by pagach
    Issue #2994894 by pagach, arthur_lorenz, fago: Extend preprocessor to...
fago’s picture

Status: Needs work » Fixed

thx, works as it should! Committed.

Status: Fixed » Closed (fixed)

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