You are here

class MediaViewMode in Media Migration 8

Drupal 7 media view mode source based on source database.

Plugin annotation


@MigrateSource(
  id = "d7_media_view_mode",
  source_module = "file_entity"
)

Hierarchy

  • class \Drupal\media_migration\Plugin\migrate\source\d7\MediaViewMode extends \Drupal\media_migration\Plugin\migrate\source\d7\DummyDrupalSqlBaseWithCountCompatibility

Expanded class hierarchy of MediaViewMode

File

src/Plugin/migrate/source/d7/MediaViewMode.php, line 13

Namespace

Drupal\media_migration\Plugin\migrate\source\d7
View source
class MediaViewMode extends DummyDrupalSqlBaseWithCountCompatibility {

  /**
   * {@inheritdoc}
   */
  protected function initializeIterator() {
    $rows = [
      [
        'mode' => 'full',
        'label' => $this
          ->getMediaViewModeLabel('full'),
      ],
      [
        'mode' => 'preview',
        'label' => $this
          ->getMediaViewModeLabel('preview'),
      ],
      [
        'mode' => 'rss',
        'label' => $this
          ->getMediaViewModeLabel('rss'),
      ],
      [
        'mode' => 'teaser',
        'label' => $this
          ->getMediaViewModeLabel('teaser'),
      ],
    ];
    if ($this
      ->moduleExists('search')) {
      $rows[] = [
        'mode' => 'search_index',
        'label' => $this
          ->getMediaViewModeLabel('search_index'),
      ];
      $rows[] = [
        'mode' => 'search_result',
        'label' => $this
          ->getMediaViewModeLabel('search_result'),
      ];
    }
    if ($this
      ->moduleExists('media_wysiwyg')) {
      $rows[] = [
        'mode' => 'wysiwyg',
        'label' => $this
          ->getMediaViewModeLabel('wysiwyg'),
      ];
    }
    return new \ArrayIterator($rows);
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return [
      'mode' => $this
        ->t('The media view mode name.'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    return [
      'mode' => [
        'type' => 'string',
        'alias' => 'mvm',
      ],
    ];
  }

  /**
   * Returns the label of the specified media view mode on the destination site.
   *
   * @param string $view_mode_id
   *   The ID of the view mode.
   *
   * @return string|null
   *   The label of the view mode, or NULL if the view mode does not exist.
   */
  protected function getMediaViewModeLabel(string $view_mode_id) {
    $view_mode_storage = $this->entityTypeManager
      ->getStorage('entity_view_mode');
    $view_mode = $view_mode_storage
      ->load("media.{$view_mode_id}");
    return $view_mode ? $view_mode
      ->label() : NULL;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MediaViewMode::fields public function
MediaViewMode::getIds public function
MediaViewMode::getMediaViewModeLabel protected function Returns the label of the specified media view mode on the destination site.
MediaViewMode::initializeIterator protected function