1. 8.5.x core/modules/node/src/Plugin/views/field/Node.php
  2. 8.5.x core/modules/node/src/Plugin/views/argument_default/Node.php
  3. 8.5.x vendor/twig/twig/lib/Twig/Function/Node.php
  4. 8.5.x core/modules/node/src/Plugin/views/wizard/Node.php
  5. 8.5.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  6. 8.5.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  7. 8.5.x core/modules/node/src/Entity/Node.php
  8. 8.5.x vendor/twig/twig/lib/Twig/Node.php
  9. 8.5.x vendor/twig/twig/lib/Twig/Filter/Node.php
  10. 8.5.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  11. 8.5.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  12. 8.5.x vendor/twig/twig/src/Node/Node.php
  13. 8.0.x core/modules/node/src/Plugin/views/field/Node.php
  14. 8.0.x core/modules/node/src/Plugin/views/wizard/Node.php
  15. 8.0.x core/modules/node/src/Plugin/migrate/builder/d6/Node.php
  16. 8.0.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  17. 8.0.x core/modules/node/src/Plugin/views/argument_default/Node.php
  18. 8.0.x core/modules/node/src/Entity/Node.php
  19. 8.0.x vendor/twig/twig/lib/Twig/Node.php
  20. 8.0.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  21. 8.0.x vendor/twig/twig/lib/Twig/Filter/Node.php
  22. 8.0.x core/modules/node/src/Plugin/migrate/builder/d7/Node.php
  23. 8.0.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  24. 8.0.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  25. 8.0.x vendor/twig/twig/lib/Twig/Function/Node.php
  26. 8.1.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  27. 8.1.x core/modules/node/src/Plugin/views/wizard/Node.php
  28. 8.1.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  29. 8.1.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  30. 8.1.x core/modules/node/src/Plugin/views/field/Node.php
  31. 8.1.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  32. 8.1.x core/modules/node/src/Entity/Node.php
  33. 8.1.x vendor/twig/twig/lib/Twig/Node.php
  34. 8.1.x core/modules/node/src/Plugin/views/argument_default/Node.php
  35. 8.1.x vendor/twig/twig/lib/Twig/Filter/Node.php
  36. 8.1.x vendor/twig/twig/lib/Twig/Function/Node.php
  37. 8.2.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  38. 8.2.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  39. 8.2.x vendor/twig/twig/lib/Twig/Function/Node.php
  40. 8.2.x vendor/twig/twig/lib/Twig/Filter/Node.php
  41. 8.2.x core/modules/node/src/Entity/Node.php
  42. 8.2.x vendor/twig/twig/lib/Twig/Node.php
  43. 8.2.x core/modules/node/src/Plugin/views/argument_default/Node.php
  44. 8.2.x core/modules/node/src/Plugin/views/field/Node.php
  45. 8.2.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  46. 8.2.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  47. 8.2.x core/modules/node/src/Plugin/views/wizard/Node.php
  48. 8.3.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  49. 8.3.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  50. 8.3.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  51. 8.3.x core/modules/node/src/Plugin/views/field/Node.php
  52. 8.3.x core/modules/node/src/Plugin/views/wizard/Node.php
  53. 8.3.x core/modules/node/src/Plugin/views/argument_default/Node.php
  54. 8.3.x vendor/twig/twig/lib/Twig/Function/Node.php
  55. 8.3.x core/modules/node/src/Entity/Node.php
  56. 8.3.x vendor/twig/twig/lib/Twig/Node.php
  57. 8.3.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  58. 8.3.x vendor/twig/twig/lib/Twig/Filter/Node.php
  59. 8.4.x core/modules/node/src/Plugin/views/wizard/Node.php
  60. 8.4.x core/modules/node/src/Plugin/views/argument_default/Node.php
  61. 8.4.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  62. 8.4.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  63. 8.4.x core/modules/node/src/Entity/Node.php
  64. 8.4.x vendor/twig/twig/lib/Twig/Function/Node.php
  65. 8.4.x core/modules/node/src/Plugin/views/field/Node.php
  66. 8.4.x vendor/twig/twig/lib/Twig/Node.php
  67. 8.4.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  68. 8.4.x vendor/twig/twig/lib/Twig/Filter/Node.php
  69. 8.4.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  70. 8.6.x vendor/twig/twig/lib/Twig/Function/Node.php
  71. 8.6.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Node.php
  72. 8.6.x core/modules/node/src/Plugin/views/argument_default/Node.php
  73. 8.6.x core/modules/node/src/Plugin/views/wizard/Node.php
  74. 8.6.x vendor/twig/twig/lib/Twig/Filter/Node.php
  75. 8.6.x vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/XML/Node.php
  76. 8.6.x core/modules/node/src/Plugin/views/field/Node.php
  77. 8.6.x core/modules/node/src/Plugin/migrate/source/d7/Node.php
  78. 8.6.x core/modules/node/src/Plugin/migrate/source/d6/Node.php
  79. 8.6.x vendor/twig/twig/src/Node/Node.php
  80. 8.6.x core/modules/node/src/Entity/Node.php
  81. 8.6.x vendor/twig/twig/lib/Twig/Node.php
  82. 4.6.x developer/hooks/node.php
  83. 4.7.x developer/hooks/node.php
  84. 5.x developer/hooks/node.php
  85. 6.x developer/hooks/node.php

Namespace

Drupal\node\Plugin\migrate\source\d7

File

core/modules/node/src/Plugin/migrate/source/d7/Node.php
View source
<?php

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

use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandler;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Drupal 7 node source from database.
 *
 * @MigrateSource(
 *   id = "d7_node",
 *   source_provider = "node"
 * )
 */
class Node extends FieldableEntity {

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, StateInterface $state, EntityManagerInterface $entity_manager, ModuleHandlerInterface $module_handler) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $migration, $state, $entity_manager);
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
    return new static($configuration, $plugin_id, $plugin_definition, $migration, $container
      ->get('state'), $container
      ->get('entity.manager'), $container
      ->get('module_handler'));
  }

  /**
   * The join options between the node and the node_revisions table.
   */
  const JOIN = 'n.vid = nr.vid';

  /**
   * {@inheritdoc}
   */
  public function query() {

    // Select node in its last revision.
    $query = $this
      ->select('node_revision', 'nr')
      ->fields('n', [
      'nid',
      'type',
      'language',
      'status',
      'created',
      'changed',
      'comment',
      'promote',
      'sticky',
      'tnid',
      'translate',
    ])
      ->fields('nr', [
      'vid',
      'title',
      'log',
      'timestamp',
    ]);
    $query
      ->addField('n', 'uid', 'node_uid');
    $query
      ->addField('nr', 'uid', 'revision_uid');
    $query
      ->innerJoin('node', 'n', static::JOIN);

    // If the content_translation module is enabled, get the source langcode
    // to fill the content_translation_source field.
    if ($this->moduleHandler
      ->moduleExists('content_translation')) {
      $query
        ->leftJoin('node', 'nt', 'n.tnid = nt.nid');
      $query
        ->addField('nt', 'language', 'source_langcode');
    }
    $this
      ->handleTranslations($query);
    if (isset($this->configuration['node_type'])) {
      $query
        ->condition('n.type', $this->configuration['node_type']);
    }
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {

    // Get Field API field values.
    foreach (array_keys($this
      ->getFields('node', $row
      ->getSourceProperty('type'))) as $field) {
      $nid = $row
        ->getSourceProperty('nid');
      $vid = $row
        ->getSourceProperty('vid');
      $row
        ->setSourceProperty($field, $this
        ->getFieldValues('node', $field, $nid, $vid));
    }

    // Make sure we always have a translation set.
    if ($row
      ->getSourceProperty('tnid') == 0) {
      $row
        ->setSourceProperty('tnid', $row
        ->getSourceProperty('nid'));
    }
    return parent::prepareRow($row);
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = [
      'nid' => $this
        ->t('Node ID'),
      'type' => $this
        ->t('Type'),
      'title' => $this
        ->t('Title'),
      'node_uid' => $this
        ->t('Node authored by (uid)'),
      'revision_uid' => $this
        ->t('Revision authored by (uid)'),
      'created' => $this
        ->t('Created timestamp'),
      'changed' => $this
        ->t('Modified timestamp'),
      'status' => $this
        ->t('Published'),
      'promote' => $this
        ->t('Promoted to front page'),
      'sticky' => $this
        ->t('Sticky at top of lists'),
      'revision' => $this
        ->t('Create new revision'),
      'language' => $this
        ->t('Language (fr, en, ...)'),
      'tnid' => $this
        ->t('The translation set id for this node'),
      'timestamp' => $this
        ->t('The timestamp the latest revision of this node was created.'),
    ];
    return $fields;
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['nid']['type'] = 'integer';
    $ids['nid']['alias'] = 'n';
    return $ids;
  }

  /**
   * Adapt our query for translations.
   *
   * @param \Drupal\Core\Database\Query\SelectInterface $query
   *   The generated query.
   */
  protected function handleTranslations(SelectInterface $query) {

    // Check whether or not we want translations.
    if (empty($this->configuration['translations'])) {

      // No translations: Yield untranslated nodes, or default translations.
      $query
        ->where('n.tnid = 0 OR n.tnid = n.nid');
    }
    else {

      // Translations: Yield only non-default translations.
      $query
        ->where('n.tnid <> 0 AND n.tnid <> n.nid');
    }
  }

}

Classes

Namesort descending Description
Node Drupal 7 node source from database.