ViewMode.php

Same filename in this branch
  1. 9 core/modules/node/src/Plugin/migrate/source/d6/ViewMode.php
Same filename in other branches
  1. 8.9.x core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php
  2. 8.9.x core/modules/node/src/Plugin/migrate/source/d6/ViewMode.php
  3. 10 core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php
  4. 10 core/modules/node/src/Plugin/migrate/source/d6/ViewMode.php
  5. 11.x core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php
  6. 11.x core/modules/node/src/Plugin/migrate/source/d6/ViewMode.php

Namespace

Drupal\field\Plugin\migrate\source\d7

File

core/modules/field/src/Plugin/migrate/source/d7/ViewMode.php

View source
<?php

namespace Drupal\field\Plugin\migrate\source\d7;


/**
 * Drupal 7 view mode source from database.
 *
 * For available configuration keys, refer to the parent classes.
 *
 * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
 *
 * @MigrateSource(
 *   id = "d7_view_mode",
 *   source_module = "field"
 * )
 */
class ViewMode extends FieldInstance {
    
    /**
     * {@inheritdoc}
     */
    protected function initializeIterator() {
        $instances = parent::initializeIterator();
        $rows = [];
        foreach ($instances->getArrayCopy() as $instance) {
            $data = unserialize($instance['data']);
            foreach (array_keys($data['display']) as $view_mode) {
                $key = $instance['entity_type'] . '.' . $view_mode;
                $rows[$key] = array_merge($instance, [
                    'view_mode' => $view_mode,
                ]);
            }
        }
        return new \ArrayIterator($rows);
    }
    
    /**
     * {@inheritdoc}
     */
    public function fields() {
        return array_merge(parent::fields(), [
            'view_mode' => $this->t('The view mode ID.'),
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIds() {
        return [
            'entity_type' => [
                'type' => 'string',
            ],
            'view_mode' => [
                'type' => 'string',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
ViewMode Drupal 7 view mode source from database.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.