Loading modules/custom_elements_thunder/custom_elements_thunder.services.yml +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ services: - { name: custom_elements_processor, priority: -50 } custom_elements.processor.thunder_quote: class: Drupal\custom_elements_thunder\Processor\ParagraphQuoteProcessor custom_elements.processor.thunder_social_media: class: Drupal\custom_elements_thunder\Processor\ParagraphSocialMediaProcessor tags: - { name: custom_elements_processor, priority: -50 } custom_elements.processor.thunder_text: Loading modules/custom_elements_thunder/src/Processor/ParagraphGalleryProcessor.php +37 −19 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphGalleryProcessor implements CustomElementProcessorInterface { use ParagraphProcessorTrait; /** * {@inheritdoc} */ Loading @@ -29,26 +31,42 @@ class ParagraphGalleryProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); if ($this->fieldIsAccessible($paragraph, 'field_media', $element)) { /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_media->entity; $media_entity = $paragraph->get('field_media')->entity; if ($this->entityIsAccessible($media_entity, $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); $sources = []; if ($this->fieldIsAccessible($media_entity, 'field_media_images', $element)) { foreach ($media_entity->field_media_images as $media_reference) { $media_image = $media_reference->entity; if ($this->entityIsAccessible($media_image, $element)) { if ($this->fieldIsAccessible($media_image, 'field_image', $element)) { $source = []; if ($this->fieldIsAccessible($media_image, 'field_copyright', $element)) { $source['copyright'] = $media_image->field_copyright->value; } if ($this->fieldIsAccessible($media_image, 'field_source', $element)) { $source['source'] = $media_image->field_source->value; } if ($this->fieldIsAccessible($media_image, 'field_description', $element)) { $source['description'] = $media_image->field_description->processed; } $sources[] = [ 'url' => $media_image->field_image->entity->uri->url, 'thumbnail-url' => $media_image->thumbnail->entity->uri->url, 'alt' => $media_image->field_image->alt->value ?? '', 'copyright' => $media_image->field_copyright->value, 'source' => $media_image->field_source->value, 'description' => $media_image->field_description->value, ]; ] + $source; } } } if ($sources) { $element->setAttribute('sources', $sources); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } } } } } Loading modules/custom_elements_thunder/src/Processor/ParagraphImageProcessor.php +23 −22 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphImageProcessor implements CustomElementProcessorInterface { use ParagraphProcessorTrait; /** * {@inheritdoc} */ Loading @@ -29,29 +31,28 @@ class ParagraphImageProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } if ($this->fieldIsAccessible($paragraph, 'field_image', $element)) { /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_image->entity; if (!$media_entity) { return; } if ($this->entityIsAccessible($media_entity, $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); if ($this->fieldIsAccessible($media_entity, 'field_image', $element)) { $element->setAttribute('src', $media_entity->field_image->entity->uri->url); if (!$media_entity->field_copyright->isEmpty()) { // Add attributes for media entity fields. if ($this->fieldIsAccessible($media_entity, 'field_copyright', $element)) { $element->setAttribute('copyright', $media_entity->field_copyright->value); } if (!$media_entity->field_source->isEmpty()) { if ($this->fieldIsAccessible($media_entity, 'field_source', $element)) { $element->setAttribute('source', $media_entity->field_source->value); } if (!$media_entity->field_description->isEmpty()) { if ($this->fieldIsAccessible($media_entity, 'field_description', $element)) { $element->setAttribute('caption', $media_entity->field_description->processed); } } } } } } modules/custom_elements_thunder/src/Processor/ParagraphInstagramProcessor.php +7 −20 Original line number Diff line number Diff line Loading @@ -2,14 +2,17 @@ namespace Drupal\custom_elements_thunder\Processor; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\Processor\CustomElementProcessorInterface; use Drupal\paragraphs\ParagraphInterface; /** * Default processor for thunder instagram, pintereset and twitter paragraphs. * Default processor for thunder instagram, pinterest and twitter paragraphs. * * @deprecated in custom_elements:1.0.0 and is removed from custom_elements:2.0.0. * Use ParagraphSocialMediaProcessor instead. * * @see https://www.drupal.org/project/custom_elements/issues/3273275 */ class ParagraphInstagramProcessor implements CustomElementProcessorInterface { class ParagraphInstagramProcessor extends ParagraphSocialMediaProcessor { /** * {@inheritdoc} Loading @@ -24,20 +27,4 @@ class ParagraphInstagramProcessor implements CustomElementProcessorInterface { } } /** * {@inheritdoc} */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_media->entity; $element->setAttribute('src', $media_entity->field_url->uri); } } modules/custom_elements_thunder/src/Processor/ParagraphLinkProcessor.php +6 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Drupal\custom_elements_thunder\Processor; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\CustomElementGeneratorTrait; use Drupal\custom_elements\Processor\CustomElementProcessorInterface; use Drupal\paragraphs\ParagraphInterface; Loading @@ -12,7 +11,7 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphLinkProcessor implements CustomElementProcessorInterface { use CustomElementGeneratorTrait; use ParagraphProcessorTrait; /** * {@inheritdoc} Loading @@ -32,14 +31,13 @@ class ParagraphLinkProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } if ($this->fieldIsAccessible($paragraph, 'field_link', $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); $element->setAttribute('title', $paragraph->field_link->title); $element->setAttribute('href', $paragraph->field_link->uri); } } } Loading
modules/custom_elements_thunder/custom_elements_thunder.services.yml +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ services: - { name: custom_elements_processor, priority: -50 } custom_elements.processor.thunder_quote: class: Drupal\custom_elements_thunder\Processor\ParagraphQuoteProcessor custom_elements.processor.thunder_social_media: class: Drupal\custom_elements_thunder\Processor\ParagraphSocialMediaProcessor tags: - { name: custom_elements_processor, priority: -50 } custom_elements.processor.thunder_text: Loading
modules/custom_elements_thunder/src/Processor/ParagraphGalleryProcessor.php +37 −19 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphGalleryProcessor implements CustomElementProcessorInterface { use ParagraphProcessorTrait; /** * {@inheritdoc} */ Loading @@ -29,26 +31,42 @@ class ParagraphGalleryProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); if ($this->fieldIsAccessible($paragraph, 'field_media', $element)) { /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_media->entity; $media_entity = $paragraph->get('field_media')->entity; if ($this->entityIsAccessible($media_entity, $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); $sources = []; if ($this->fieldIsAccessible($media_entity, 'field_media_images', $element)) { foreach ($media_entity->field_media_images as $media_reference) { $media_image = $media_reference->entity; if ($this->entityIsAccessible($media_image, $element)) { if ($this->fieldIsAccessible($media_image, 'field_image', $element)) { $source = []; if ($this->fieldIsAccessible($media_image, 'field_copyright', $element)) { $source['copyright'] = $media_image->field_copyright->value; } if ($this->fieldIsAccessible($media_image, 'field_source', $element)) { $source['source'] = $media_image->field_source->value; } if ($this->fieldIsAccessible($media_image, 'field_description', $element)) { $source['description'] = $media_image->field_description->processed; } $sources[] = [ 'url' => $media_image->field_image->entity->uri->url, 'thumbnail-url' => $media_image->thumbnail->entity->uri->url, 'alt' => $media_image->field_image->alt->value ?? '', 'copyright' => $media_image->field_copyright->value, 'source' => $media_image->field_source->value, 'description' => $media_image->field_description->value, ]; ] + $source; } } } if ($sources) { $element->setAttribute('sources', $sources); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } } } } } Loading
modules/custom_elements_thunder/src/Processor/ParagraphImageProcessor.php +23 −22 Original line number Diff line number Diff line Loading @@ -11,6 +11,8 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphImageProcessor implements CustomElementProcessorInterface { use ParagraphProcessorTrait; /** * {@inheritdoc} */ Loading @@ -29,29 +31,28 @@ class ParagraphImageProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } if ($this->fieldIsAccessible($paragraph, 'field_image', $element)) { /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_image->entity; if (!$media_entity) { return; } if ($this->entityIsAccessible($media_entity, $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); if ($this->fieldIsAccessible($media_entity, 'field_image', $element)) { $element->setAttribute('src', $media_entity->field_image->entity->uri->url); if (!$media_entity->field_copyright->isEmpty()) { // Add attributes for media entity fields. if ($this->fieldIsAccessible($media_entity, 'field_copyright', $element)) { $element->setAttribute('copyright', $media_entity->field_copyright->value); } if (!$media_entity->field_source->isEmpty()) { if ($this->fieldIsAccessible($media_entity, 'field_source', $element)) { $element->setAttribute('source', $media_entity->field_source->value); } if (!$media_entity->field_description->isEmpty()) { if ($this->fieldIsAccessible($media_entity, 'field_description', $element)) { $element->setAttribute('caption', $media_entity->field_description->processed); } } } } } }
modules/custom_elements_thunder/src/Processor/ParagraphInstagramProcessor.php +7 −20 Original line number Diff line number Diff line Loading @@ -2,14 +2,17 @@ namespace Drupal\custom_elements_thunder\Processor; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\Processor\CustomElementProcessorInterface; use Drupal\paragraphs\ParagraphInterface; /** * Default processor for thunder instagram, pintereset and twitter paragraphs. * Default processor for thunder instagram, pinterest and twitter paragraphs. * * @deprecated in custom_elements:1.0.0 and is removed from custom_elements:2.0.0. * Use ParagraphSocialMediaProcessor instead. * * @see https://www.drupal.org/project/custom_elements/issues/3273275 */ class ParagraphInstagramProcessor implements CustomElementProcessorInterface { class ParagraphInstagramProcessor extends ParagraphSocialMediaProcessor { /** * {@inheritdoc} Loading @@ -24,20 +27,4 @@ class ParagraphInstagramProcessor implements CustomElementProcessorInterface { } } /** * {@inheritdoc} */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } /** @var \Drupal\media\Entity\Media $media_entity */ $media_entity = $paragraph->field_media->entity; $element->setAttribute('src', $media_entity->field_url->uri); } }
modules/custom_elements_thunder/src/Processor/ParagraphLinkProcessor.php +6 −8 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ namespace Drupal\custom_elements_thunder\Processor; use Drupal\custom_elements\CustomElement; use Drupal\custom_elements\CustomElementGeneratorTrait; use Drupal\custom_elements\Processor\CustomElementProcessorInterface; use Drupal\paragraphs\ParagraphInterface; Loading @@ -12,7 +11,7 @@ use Drupal\paragraphs\ParagraphInterface; */ class ParagraphLinkProcessor implements CustomElementProcessorInterface { use CustomElementGeneratorTrait; use ParagraphProcessorTrait; /** * {@inheritdoc} Loading @@ -32,14 +31,13 @@ class ParagraphLinkProcessor implements CustomElementProcessorInterface { */ public function addtoElement($paragraph, CustomElement $element, $viewMode) { assert($paragraph instanceof ParagraphInterface); // Always add a title attribute if field_title is there. if (isset($paragraph->field_title) && $paragraph->field_title->value) { $element->setAttribute('title', $paragraph->field_title->value); } if ($this->fieldIsAccessible($paragraph, 'field_link', $element)) { // Add common data with trait. $this->addtoElementCommon($paragraph, $element); $element->setAttribute('title', $paragraph->field_link->title); $element->setAttribute('href', $paragraph->field_link->uri); } } }