EntityNodeType.php

Same filename in other branches
  1. 9 core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php
  2. 8.9.x core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php
  3. 11.x core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php

Namespace

Drupal\node\Plugin\migrate\destination

File

core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php

View source
<?php

namespace Drupal\node\Plugin\migrate\destination;

use Drupal\migrate\Attribute\MigrateDestination;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
use Drupal\migrate\Row;

/**
 * Migration destination for node type entity.
 */
class EntityNodeType extends EntityConfigBase {
    
    /**
     * {@inheritdoc}
     */
    public function getEntity(Row $row, array $old_destination_id_values) {
        
        /** @var \Drupal\node\NodeTypeInterface $node_type */
        $node_type = parent::getEntity($row, $old_destination_id_values);
        // Config schema does not allow description or help text to be empty.
        if ($node_type->getDescription() === '') {
            $node_type->set('description', NULL);
        }
        if ($node_type->getHelp() === '') {
            $node_type->set('help', NULL);
        }
        return $node_type;
    }
    
    /**
     * {@inheritdoc}
     */
    public function import(Row $row, array $old_destination_id_values = []) {
        $entity_ids = parent::import($row, $old_destination_id_values);
        if ($row->getDestinationProperty('create_body')) {
            $node_type = $this->storage
                ->load(reset($entity_ids));
            node_add_body_field($node_type, $row->getDestinationProperty('create_body_label'));
        }
        return $entity_ids;
    }

}

Classes

Title Deprecated Summary
EntityNodeType Migration destination for node type entity.

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