Commit 5c888f8b authored by Ian McLean's avatar Ian McLean Committed by Joshua Sedler
Browse files

Issue #3305887 by imclean: Add option to use media Name as caption

parent 294aabec
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -155,6 +155,10 @@ class PhotoswipePreprocessProcessor implements ContainerInjectionInterface {
          $caption = $this->imageDTO->getEntity()->label() ?: $this->imageDTO->getAlt();
          break;

        case 'media_name':
          $caption = $this->imageDTO->getItem()->getParent()->getEntity()->label();
          break;

        case 'custom':
          $entity_type = $this->imageDTO->getEntity()->getEntityTypeId();
          $caption = $this->token->replace($settings['photoswipe_caption_custom'],
+6 −0
Original line number Diff line number Diff line
@@ -200,6 +200,11 @@ class PhotoswipeFieldFormatter extends FormatterBase {
      'entity_label' => $this->t('Entity label'),
      'custom' => $this->t('Custom (with tokens)'),
    ];
    // Add media entity name if the target is a media entity:
    $field_settings = $this->getFieldSettings();
    if (isset($field_settings['target_type']) && $field_settings['target_type'] === 'media') {
      $caption_options['media_name'] = $this->t('Media entity name');
    }

    $element = $this->addEntityReferenceSettings($element);

@@ -386,6 +391,7 @@ class PhotoswipeFieldFormatter extends FormatterBase {
        'alt' => $this->t('Image alt tag'),
        'title' => $this->t('Image title tag'),
        'entity_label' => $this->t('Entity label'),
        'media_name' => $this->t('Media entity name'),
        'custom' => $this->t('Custom (with tokens)'),
      ];
      if (array_key_exists($this->getSetting('photoswipe_caption'), $caption_options)) {