FieldInstancePerViewMode.php

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

Namespace

Drupal\field\Plugin\migrate\source\d7

File

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

View source
<?php

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


/**
 * Drupal 7 field instance per view mode source class.
 *
 * For available configuration keys, refer to the parent classes.
 *
 * @see \Drupal\field\Plugin\migrate\source\d7\FieldInstance
 * @see \Drupal\migrate\Plugin\migrate\source\SqlBase
 * @see \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
 *
 * @MigrateSource(
 *   id = "d7_field_instance_per_view_mode",
 *   source_module = "field"
 * )
 */
class FieldInstancePerViewMode extends FieldInstance {
    
    /**
     * {@inheritdoc}
     */
    protected function initializeIterator() {
        $instances = parent::initializeIterator();
        $rows = [];
        foreach ($instances->getArrayCopy() as $instance) {
            $data = unserialize($instance['data']);
            foreach ($data['display'] as $view_mode => $formatter) {
                $rows[] = array_merge($instance, [
                    'view_mode' => $view_mode,
                    'formatter' => $formatter,
                ]);
            }
        }
        return new \ArrayIterator($rows);
    }
    
    /**
     * {@inheritdoc}
     */
    public function fields() {
        return array_merge(parent::fields(), [
            'view_mode' => $this->t('The original machine name of the view mode.'),
            'formatter' => $this->t('The formatter settings.'),
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIds() {
        return [
            'entity_type' => [
                'type' => 'string',
            ],
            'bundle' => [
                'type' => 'string',
            ],
            'view_mode' => [
                'type' => 'string',
            ],
            'field_name' => [
                'type' => 'string',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
FieldInstancePerViewMode Drupal 7 field instance per view mode source class.

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