Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -187,13 +187,6 @@ class Term extends ContentEntityBase implements TermInterface {
|
|||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getChangedTime() {
|
||||
return $this->get('changed')->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -122,48 +122,6 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
|
|||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
|
||||
parent::postSave($storage, $update);
|
||||
|
||||
if ($update && $this->getOriginalId() != $this->id() && !$this->isSyncing()) {
|
||||
// Reflect machine name changes in the definitions of existing 'taxonomy'
|
||||
// fields.
|
||||
$field_ids = array();
|
||||
$field_map = \Drupal::entityManager()->getFieldMapByFieldType('entity_reference');
|
||||
foreach ($field_map as $entity_type => $field_storages) {
|
||||
foreach ($field_storages as $field_storage => $info) {
|
||||
$field_ids[] = $entity_type . '.' . $field_storage;
|
||||
}
|
||||
}
|
||||
|
||||
$field_storages = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple($field_ids);
|
||||
$taxonomy_fields = array_filter($field_storages, function ($field_storage) {
|
||||
return $field_storage->getType() == 'entity_reference' && $field_storage->getSetting('target_type') == 'taxonomy_term';
|
||||
});
|
||||
|
||||
foreach ($taxonomy_fields as $field_storage) {
|
||||
$update_storage = FALSE;
|
||||
|
||||
$allowed_values = $field_storage->getSetting('allowed_values');
|
||||
foreach ($allowed_values as &$value) {
|
||||
if ($value['vocabulary'] == $this->getOriginalId()) {
|
||||
$value['vocabulary'] = $this->id();
|
||||
$update_storage = TRUE;
|
||||
}
|
||||
}
|
||||
$field_storage->setSetting('allowed_values', $allowed_values);
|
||||
|
||||
if ($update_storage) {
|
||||
$field_storage->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$storage->resetCache($update ? array($this->getOriginalId()) : array());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -207,7 +207,7 @@ class OverviewTerms extends FormBase {
|
|||
$form['terms'] = array(
|
||||
'#type' => 'table',
|
||||
'#header' => array($this->t('Name'), $this->t('Weight'), $this->t('Operations')),
|
||||
'#empty' => $this->t('No terms available. <a href="@link">Add term</a>.', array('@link' => $this->url('entity.taxonomy_term.add_form', array('taxonomy_vocabulary' => $taxonomy_vocabulary->id())))),
|
||||
'#empty' => $this->t('No terms available. <a href=":link">Add term</a>.', array(':link' => $this->url('entity.taxonomy_term.add_form', array('taxonomy_vocabulary' => $taxonomy_vocabulary->id())))),
|
||||
'#attributes' => array(
|
||||
'id' => 'taxonomy',
|
||||
),
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
namespace Drupal\taxonomy\Plugin\EntityReferenceSelection;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Core\Database\Query\SelectInterface;
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase;
|
||||
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
|
||||
|
@ -24,7 +24,7 @@ use Drupal\taxonomy\Entity\Vocabulary;
|
|||
* weight = 1
|
||||
* )
|
||||
*/
|
||||
class TermSelection extends SelectionBase {
|
||||
class TermSelection extends DefaultSelection {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -73,7 +73,7 @@ class TermSelection extends SelectionBase {
|
|||
if ($vocabulary = Vocabulary::load($bundle)) {
|
||||
if ($terms = $this->entityManager->getStorage('taxonomy_term')->loadTree($vocabulary->id(), 0, NULL, TRUE)) {
|
||||
foreach ($terms as $term) {
|
||||
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . SafeMarkup::checkPlain($term->getName());
|
||||
$options[$vocabulary->id()][$term->id()] = str_repeat('-', $term->depth) . Html::escape($term->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function viewElements(FieldItemListInterface $items) {
|
||||
public function viewElements(FieldItemListInterface $items, $langcode) {
|
||||
$parent_entity = $items->getEntity();
|
||||
$elements = array();
|
||||
|
||||
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
|
||||
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
|
||||
$parent_entity->rss_elements[] = array(
|
||||
'key' => 'category',
|
||||
'value' => $entity->label(),
|
||||
|
|
|
@ -78,11 +78,10 @@ class TermNode extends BuilderBase implements ContainerFactoryPluginInterface {
|
|||
// Only process the destination ID properties.
|
||||
$process = array_intersect_key($template['process'], $migration->getDestinationPlugin()->getIds());
|
||||
|
||||
foreach ($migration->getSourcePlugin()->getIterator() as $source_row) {
|
||||
$row = new Row($source_row, $source_row);
|
||||
foreach ($migration->getSourcePlugin() as $source_row) {
|
||||
// Process the row to generate the expected destination ID.
|
||||
$executable->processRow($row, $process);
|
||||
$map[$row->getSourceProperty('vid')] = $row->getDestinationProperty('vid');
|
||||
$executable->processRow($source_row, $process);
|
||||
$map[$source_row->getSourceProperty('vid')] = $source_row->getDestinationProperty('vid');
|
||||
}
|
||||
|
||||
return $map;
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Plugin\migrate\cckfield\TaxonomyTermReference.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Plugin\migrate\cckfield;
|
||||
|
||||
use Drupal\migrate\Entity\MigrationInterface;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
|
||||
|
||||
/**
|
||||
* @PluginID("taxonomy_term_reference")
|
||||
*/
|
||||
class TaxonomyTermReference extends CckFieldPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFieldFormatterMap() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
|
||||
$process = array(
|
||||
'plugin' => 'iterator',
|
||||
'source' => $field_name,
|
||||
'process' => array(
|
||||
'target_id' => 'tid',
|
||||
),
|
||||
);
|
||||
$migration->setProcessOfProperty($field_name, $process);
|
||||
}
|
||||
|
||||
}
|
|
@ -2,41 +2,62 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\Term.
|
||||
* Contains \Drupal\taxonomy\Plugin\migrate\source\Term.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
|
||||
namespace Drupal\taxonomy\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 taxonomy terms source from database.
|
||||
* Taxonomy term source from database.
|
||||
*
|
||||
* @todo Support term_relation, term_synonym table if possible.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_taxonomy_term",
|
||||
* id = "taxonomy_term",
|
||||
* source_provider = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class Term extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* Name of the term data table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $termDataTable;
|
||||
|
||||
/**
|
||||
* Name of the term hierarchy table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $termHierarchyTable;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
// Note the explode - this supports the (admittedly unusual) case of
|
||||
// consolidating multiple vocabularies into one.
|
||||
$query = $this->select('term_data', 'td')
|
||||
->fields('td', array('tid', 'vid', 'name', 'description', 'weight'))
|
||||
// This works, but we cannot test that, because there is no support for
|
||||
// distinct() in FakeSelect, yet.
|
||||
if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
|
||||
$this->termDataTable = 'taxonomy_term_data';
|
||||
$this->termHierarchyTable = 'taxonomy_term_hierarchy';
|
||||
}
|
||||
else {
|
||||
$this->termDataTable = 'term_data';
|
||||
$this->termHierarchyTable = 'term_hierarchy';
|
||||
}
|
||||
|
||||
$query = $this->select($this->termDataTable, 'td')
|
||||
->fields('td')
|
||||
->distinct()
|
||||
->orderBy('tid');
|
||||
|
||||
if (isset($this->configuration['vocabulary'])) {
|
||||
$query->condition('vid', $this->configuration['vocabulary'], 'IN');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -44,7 +65,7 @@ class Term extends DrupalSqlBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
$fields = array(
|
||||
'tid' => $this->t('The term ID.'),
|
||||
'vid' => $this->t('Existing term VID'),
|
||||
'name' => $this->t('The name of the term.'),
|
||||
|
@ -52,6 +73,10 @@ class Term extends DrupalSqlBase {
|
|||
'weight' => $this->t('Weight'),
|
||||
'parent' => $this->t("The Drupal term IDs of the term's parents."),
|
||||
);
|
||||
if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
|
||||
$fields['format'] = $this->t('Format of the term description.');
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,12 +84,13 @@ class Term extends DrupalSqlBase {
|
|||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
// Find parents for this row.
|
||||
$parents = $this->select('term_hierarchy', 'th')
|
||||
$parents = $this->select($this->termHierarchyTable, 'th')
|
||||
->fields('th', array('parent', 'tid'))
|
||||
->condition('tid', $row->getSourceProperty('tid'))
|
||||
->execute()
|
||||
->fetchCol();
|
||||
$row->setSourceProperty('parent', $parents);
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
|||
*/
|
||||
class TermNode extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
/**
|
||||
* The join options between the node and the term node table.
|
||||
*/
|
||||
const JOIN = 'tn.vid = n.vid';
|
||||
|
@ -30,7 +30,6 @@ class TermNode extends DrupalSqlBase {
|
|||
*/
|
||||
public function query() {
|
||||
$query = $this->select('term_node', 'tn')
|
||||
// @todo: working, but not is there support for distinct() in FakeSelect?
|
||||
->distinct()
|
||||
->fields('tn', array('nid', 'vid'))
|
||||
->fields('n', array('type'));
|
||||
|
@ -38,7 +37,6 @@ class TermNode extends DrupalSqlBase {
|
|||
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', array(':vid' => $this->configuration['vid']));
|
||||
$query->innerJoin('node', 'n', static::JOIN);
|
||||
return $query;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 vocabularies source from database.
|
||||
|
@ -17,7 +18,48 @@ use Drupal\migrate\Row;
|
|||
* source_provider = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class Vocabulary extends VocabularyBase {
|
||||
class Vocabulary extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('vocabulary', 'v')
|
||||
->fields('v', array(
|
||||
'vid',
|
||||
'name',
|
||||
'description',
|
||||
'help',
|
||||
'relations',
|
||||
'hierarchy',
|
||||
'multiple',
|
||||
'required',
|
||||
'tags',
|
||||
'module',
|
||||
'weight',
|
||||
));
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'vid' => $this->t('The vocabulary ID.'),
|
||||
'name' => $this->t('The name of the vocabulary.'),
|
||||
'description' => $this->t('The description of the vocabulary.'),
|
||||
'help' => $this->t('Help text to display for the vocabulary.'),
|
||||
'relations' => $this->t('Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'),
|
||||
'multiple' => $this->t('Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)'),
|
||||
'required' => $this->t('Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'tags' => $this->t('Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'),
|
||||
'parents' => $this->t("The Drupal term IDs of the term's parents."),
|
||||
'node_types' => $this->t('The names of the node types the vocabulary may be used with.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Plugin\migrate\source\d6\VocabularyBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Plugin\migrate\source\d6;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 6 vocabularies source base.
|
||||
*/
|
||||
abstract class VocabularyBase extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('vocabulary', 'v')
|
||||
->fields('v', array(
|
||||
'vid',
|
||||
'name',
|
||||
'description',
|
||||
'help',
|
||||
'relations',
|
||||
'hierarchy',
|
||||
'multiple',
|
||||
'required',
|
||||
'tags',
|
||||
'module',
|
||||
'weight',
|
||||
));
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'vid' => $this->t('The vocabulary ID.'),
|
||||
'name' => $this->t('The name of the vocabulary.'),
|
||||
'description' => $this->t('The description of the vocabulary.'),
|
||||
'help' => $this->t('Help text to display for the vocabulary.'),
|
||||
'relations' => $this->t('Whether or not related terms are enabled within the vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'),
|
||||
'multiple' => $this->t('Whether or not multiple terms from this vocabulary may be assigned to a node. (0 = disabled, 1 = enabled)'),
|
||||
'required' => $this->t('Whether or not terms are required for nodes using this vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'tags' => $this->t('Whether or not free tagging is enabled for the vocabulary. (0 = disabled, 1 = enabled)'),
|
||||
'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'),
|
||||
'parents' => $this->t("The Drupal term IDs of the term's parents."),
|
||||
'node_types' => $this->t('The names of the node types the vocabulary may be used with.'),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -22,10 +22,8 @@ class VocabularyPerType extends Vocabulary {
|
|||
*/
|
||||
public function query() {
|
||||
$query = parent::query();
|
||||
$query->fields('nt', array(
|
||||
'type',
|
||||
));
|
||||
$query->join('vocabulary_node_types', 'nt', 'v.vid = nt.vid');
|
||||
$query->fields('nt', array('type'));
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Plugin\migrate\source\d7\Vocabulary.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Plugin\migrate\source\d7;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
|
||||
/**
|
||||
* Drupal 7 vocabularies source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d7_taxonomy_vocabulary",
|
||||
* source_provider = "taxonomy"
|
||||
* )
|
||||
*/
|
||||
class Vocabulary extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
$query = $this->select('taxonomy_vocabulary', 'v')
|
||||
->fields('v', array(
|
||||
'vid',
|
||||
'name',
|
||||
'description',
|
||||
'hierarchy',
|
||||
'module',
|
||||
'weight',
|
||||
'machine_name',
|
||||
));
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'vid' => $this->t('The vocabulary ID.'),
|
||||
'name' => $this->t('The name of the vocabulary.'),
|
||||
'description' => $this->t('The description of the vocabulary.'),
|
||||
'hierarchy' => $this->t('The type of hierarchy allowed within the vocabulary. (0 = disabled, 1 = single, 2 = multiple)'),
|
||||
'module' => $this->t('Module responsible for the vocabulary.'),
|
||||
'weight' => $this->t('The weight of the vocabulary in relation to other vocabularies.'),
|
||||
'machine_name' => $this->t('Unique achine name of the vocabulary.')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['vid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@ use Drupal\Core\Entity\EntityStorageInterface;
|
|||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\views\Plugin\views\argument\ArgumentPluginBase;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -140,7 +139,7 @@ class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPlugin
|
|||
function title() {
|
||||
$term = $this->termStorage->load($this->argument);
|
||||
if (!empty($term)) {
|
||||
return SafeMarkup::checkPlain($term->getName());
|
||||
return $term->getName();
|
||||
}
|
||||
// TODO review text
|
||||
return $this->t('No name');
|
||||
|
|
|
@ -10,7 +10,6 @@ namespace Drupal\taxonomy\Plugin\views\argument;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
|
||||
use Drupal\views\Plugin\views\argument\NumericArgument;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
@ -56,7 +55,7 @@ class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterfac
|
|||
if ($this->argument) {
|
||||
$term = $this->termStorage->load($this->argument);
|
||||
if (!empty($term)) {
|
||||
return SafeMarkup::checkPlain($term->getName());
|
||||
return $term->getName();
|
||||
}
|
||||
}
|
||||
// TODO review text
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\taxonomy\Plugin\views\argument;
|
||||
|
||||
use Drupal\views\Plugin\views\argument\NumericArgument;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\taxonomy\VocabularyStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -63,7 +62,7 @@ class VocabularyVid extends NumericArgument {
|
|||
function title() {
|
||||
$vocabulary = $this->vocabularyStorage->load($this->argument);
|
||||
if ($vocabulary) {
|
||||
return SafeMarkup::checkPlain($vocabulary->label());
|
||||
return $vocabulary->label();
|
||||
}
|
||||
|
||||
return $this->t('No vocabulary');
|
||||
|
|
|
@ -7,10 +7,11 @@
|
|||
|
||||
namespace Drupal\taxonomy\Plugin\views\argument_default;
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Cache\CacheableDependencyInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Routing\RouteMatchInterface;
|
||||
use Drupal\taxonomy\TermInterface;
|
||||
use Drupal\views\Plugin\CacheablePluginInterface;
|
||||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
|
||||
|
@ -28,7 +29,7 @@ use Drupal\taxonomy\VocabularyStorageInterface;
|
|||
* title = @Translation("Taxonomy term ID from URL")
|
||||
* )
|
||||
*/
|
||||
class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface {
|
||||
class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
|
||||
|
||||
/**
|
||||
* The route match.
|
||||
|
@ -216,8 +217,8 @@ class Tid extends ArgumentDefaultPluginBase implements CacheablePluginInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isCacheable() {
|
||||
return TRUE;
|
||||
public function getCacheMaxAge() {
|
||||
return Cache::PERMANENT;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,6 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Plugin\views\field\PrerenderList;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Drupal\taxonomy\VocabularyStorageInterface;
|
||||
|
@ -153,7 +152,7 @@ class TaxonomyIndexTid extends PrerenderList {
|
|||
$this->items[$node_nid][$tid]['name'] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
|
||||
$this->items[$node_nid][$tid]['tid'] = $tid;
|
||||
$this->items[$node_nid][$tid]['vocabulary_vid'] = $term->getVocabularyId();
|
||||
$this->items[$node_nid][$tid]['vocabulary'] = SafeMarkup::checkPlain($vocabularies[$term->getVocabularyId()]->label());
|
||||
$this->items[$node_nid][$tid]['vocabulary'] = $vocabularies[$term->getVocabularyId()]->label();
|
||||
|
||||
if (!empty($this->options['link_to_taxonomy'])) {
|
||||
$this->items[$node_nid][$tid]['make_link'] = TRUE;
|
||||
|
|
|
@ -28,7 +28,8 @@ class TermName extends Field {
|
|||
foreach ($items as &$item) {
|
||||
// Replace spaces with hyphens.
|
||||
$name = $item['raw']->get('value')->getValue();
|
||||
$item['rendered']['#markup'] = str_replace(' ', '-', $name);
|
||||
// @todo Add link support https://www.drupal.org/node/2567745
|
||||
$item['rendered']['#context']['value'] = str_replace(' ', '-', $name);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
|
|
|
@ -16,7 +16,6 @@ use Drupal\taxonomy\VocabularyStorageInterface;
|
|||
use Drupal\views\ViewExecutable;
|
||||
use Drupal\views\Plugin\views\display\DisplayPluginBase;
|
||||
use Drupal\views\Plugin\views\filter\ManyToOne;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Component\Utility\Tags;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
@ -154,7 +153,7 @@ class TaxonomyIndexTid extends ManyToOne {
|
|||
$vocabulary = $this->vocabularyStorage->load($this->options['vid']);
|
||||
if (empty($vocabulary) && $this->options['limit']) {
|
||||
$form['markup'] = array(
|
||||
'#markup' => '<div class="form-item">' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '</div>',
|
||||
'#markup' => '<div class="js-form-item form-item">' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '</div>',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -183,7 +182,7 @@ class TaxonomyIndexTid extends ManyToOne {
|
|||
if ($tree) {
|
||||
foreach ($tree as $term) {
|
||||
$choice = new \stdClass();
|
||||
$choice->option = array($term->id() => str_repeat('-', $term->depth) . SafeMarkup::checkPlain(\Drupal::entityManager()->getTranslationFromContext($term)->label()));
|
||||
$choice->option = array($term->id() => str_repeat('-', $term->depth) . \Drupal::entityManager()->getTranslationFromContext($term)->label());
|
||||
$options[] = $choice;
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +200,7 @@ class TaxonomyIndexTid extends ManyToOne {
|
|||
}
|
||||
$terms = Term::loadMultiple($query->execute());
|
||||
foreach ($terms as $term) {
|
||||
$options[$term->id()] = SafeMarkup::checkPlain(\Drupal::entityManager()->getTranslationFromContext($term)->label());
|
||||
$options[$term->id()] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +358,7 @@ class TaxonomyIndexTid extends ManyToOne {
|
|||
$this->value = array_filter($this->value);
|
||||
$terms = Term::loadMultiple($this->value);
|
||||
foreach ($terms as $term) {
|
||||
$this->valueOptions[$term->id()] = SafeMarkup::checkPlain(\Drupal::entityManager()->getTranslationFromContext($term)->label());
|
||||
$this->valueOptions[$term->id()] = \Drupal::entityManager()->getTranslationFromContext($term)->label();
|
||||
}
|
||||
}
|
||||
return parent::adminSummary();
|
||||
|
|
|
@ -22,7 +22,7 @@ class TermAccessControlHandler extends EntityAccessControlHandler {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
return AccessResult::allowedIfHasPermission($account, 'access content');
|
||||
|
|
|
@ -78,7 +78,7 @@ class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface {
|
|||
|
||||
// This breadcrumb builder is based on a route parameter, and hence it
|
||||
// depends on the 'route' cache context.
|
||||
$breadcrumb->setCacheContexts(['route']);
|
||||
$breadcrumb->addCacheContexts(['route']);
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@ class TermViewBuilder extends EntityViewBuilder {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode, $langcode = NULL) {
|
||||
parent::alterBuild($build, $entity, $display, $view_mode, $langcode);
|
||||
protected function alterBuild(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
|
||||
parent::alterBuild($build, $entity, $display, $view_mode);
|
||||
$build['#contextual_links']['taxonomy_term'] = array(
|
||||
'route_parameters' => array('taxonomy_term' => $entity->id()),
|
||||
'metadata' => array('changed' => $entity->getChangedTime()),
|
||||
|
|
|
@ -38,7 +38,7 @@ class LoadMultipleTest extends TaxonomyTestBase {
|
|||
// Load the terms from the vocabulary.
|
||||
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
|
||||
$count = count($terms);
|
||||
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. !count terms.', array('!count' => $count)));
|
||||
$this->assertEqual($count, 5, format_string('Correct number of terms were loaded. @count terms.', array('@count' => $count)));
|
||||
|
||||
// Load the same terms again by tid.
|
||||
$terms2 = Term::loadMultiple(array_keys($terms));
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyConfigsTest.
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\MigrateTaxonomyConfigsTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
namespace Drupal\taxonomy\Tests\Migrate;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
@ -20,9 +20,7 @@ class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
|
|||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('taxonomy');
|
||||
|
||||
|
@ -31,7 +29,7 @@ class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d6_taxonomy_settings');
|
||||
$this->executeMigration('taxonomy_settings');
|
||||
}
|
||||
|
||||
/**
|
|
@ -17,23 +17,18 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
*/
|
||||
class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
|
||||
|
||||
static $modules = array('taxonomy', 'text');
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('taxonomy');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
|
||||
$this->prepareMigrations(array(
|
||||
'd6_taxonomy_vocabulary' => array(
|
||||
array(array(1), array('vocabulary_1_i_0_')),
|
||||
array(array(2), array('vocabulary_2_i_1_')),
|
||||
array(array(3), array('vocabulary_3_i_2_')),
|
||||
)));
|
||||
$this->executeMigration('d6_taxonomy_term');
|
||||
$this->executeMigrations(['d6_taxonomy_vocabulary', 'd6_taxonomy_term']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
|
@ -18,9 +19,7 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('taxonomy');
|
||||
|
||||
|
@ -39,7 +38,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
|
|||
for ($i = 0; $i < 3; $i++) {
|
||||
$j = $i + 1;
|
||||
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
|
||||
$this->assertIdentical(entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
|
||||
$this->assertIdentical(Migration::load('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
|
||||
$this->assertIdentical("vocabulary $j (i=$i)", $vocabulary->label());
|
||||
$this->assertIdentical("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
|
||||
$this->assertIdentical($i, $vocabulary->getHierarchy());
|
||||
|
|
|
@ -7,32 +7,29 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade taxonomy term node associations.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateTermNodeRevisionTest extends MigrateTermNodeTestBase {
|
||||
class MigrateTermNodeRevisionTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$id_mappings = array(
|
||||
'd6_term_node:*' => array(
|
||||
array(array(2), array(1)),
|
||||
),
|
||||
'd6_node_revision:*' => array(
|
||||
array(array(2), array(2)),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$migrations = Migration::loadMultiple(['d6_term_node_revision:*']);
|
||||
array_walk($migrations, [$this, 'executeMigration']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->migrateContent(TRUE);
|
||||
$this->migrateTaxonomy();
|
||||
$this->executeMigrations(['d6_term_node:*', 'd6_term_node_revision:*']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate\MigrateExecutable;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
|
||||
/**
|
||||
|
@ -16,33 +15,33 @@ use Drupal\node\Entity\Node;
|
|||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateTermNodeTest extends MigrateTermNodeTestBase {
|
||||
class MigrateTermNodeTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$id_mappings = array(
|
||||
'd6_node:*' => array(
|
||||
array(
|
||||
array(0),
|
||||
array(0),
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$migrations = Migration::loadMultiple(['d6_term_node:*']);
|
||||
array_walk($migrations, [$this, 'executeMigration']);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->migrateContent();
|
||||
$this->migrateTaxonomy();
|
||||
$this->executeMigrations(['d6_term_node:*']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 6 term-node association to Drupal 8 migration.
|
||||
*/
|
||||
public function testTermNode() {
|
||||
$node_storage = $this->container->get('entity.manager')->getStorage('node');
|
||||
$node_storage->resetCache(array(1, 2));
|
||||
$nodes = Node::loadMultiple(array(1, 2));
|
||||
$this->container->get('entity.manager')
|
||||
->getStorage('node')
|
||||
->resetCache([1, 2]);
|
||||
|
||||
$nodes = Node::loadMultiple([1, 2]);
|
||||
$node = $nodes[1];
|
||||
$this->assertIdentical(1, count($node->vocabulary_1_i_0_));
|
||||
$this->assertIdentical('1', $node->vocabulary_1_i_0_[0]->target_id);
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeTestBase.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Base class for Taxonomy/Node migration tests.
|
||||
*/
|
||||
abstract class MigrateTermNodeTestBase extends MigrateDrupal6TestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array('node', 'taxonomy', 'text', 'filter', 'entity_reference');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installSchema('node', array('node_access'));
|
||||
|
||||
$vocabulary = entity_create('taxonomy_vocabulary', array(
|
||||
'vid' => 'test',
|
||||
));
|
||||
$vocabulary->save();
|
||||
$node_type = entity_create('node_type', array('type' => 'story'));
|
||||
$node_type->save();
|
||||
foreach (array('vocabulary_1_i_0_', 'vocabulary_2_i_1_', 'vocabulary_3_i_2_') as $name) {
|
||||
$handler_settings = array(
|
||||
'target_bundles' => array(
|
||||
$vocabulary->id() => $vocabulary->id(),
|
||||
),
|
||||
'auto_create' => TRUE,
|
||||
);
|
||||
$this->createEntityReferenceField('node', 'story', $name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||
}
|
||||
$id_mappings = array(
|
||||
'd6_vocabulary_field_instance' => array(
|
||||
array(array(1, 'page'), array('node', 'page', 'test')),
|
||||
),
|
||||
'd6_vocabulary_entity_display' => array(
|
||||
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
|
||||
),
|
||||
'd6_vocabulary_entity_form_display' => array(
|
||||
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
|
||||
),
|
||||
'd6_node' => array(
|
||||
array(array(1), array(1)),
|
||||
array(array(2), array(2)),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
$vids = array(1, 2, 3);
|
||||
for ($i = 1; $i <= 2; $i++) {
|
||||
$node = entity_create('node', array(
|
||||
'type' => 'story',
|
||||
'nid' => $i,
|
||||
'vid' => array_shift($vids),
|
||||
'title' => $this->randomString(),
|
||||
));
|
||||
$node->enforceIsNew();
|
||||
$node->save();
|
||||
if ($i == 1) {
|
||||
$node->vid->value = array_shift($vids);
|
||||
$node->enforceIsNew(FALSE);
|
||||
$node->setNewRevision();
|
||||
$node->isDefaultRevision(FALSE);
|
||||
$node->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -17,59 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array('field', 'node', 'taxonomy', 'text', 'entity_reference');
|
||||
public static $modules = ['field', 'taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'tags',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => array(
|
||||
'target_type' => 'taxonomy_term',
|
||||
),
|
||||
))->save();
|
||||
|
||||
foreach (array('page', 'article', 'story') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
entity_create('field_config', array(
|
||||
'label' => 'Tags',
|
||||
'description' => '',
|
||||
'field_name' => 'tags',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'required' => 1,
|
||||
'settings' => array(
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
'target_bundles' => array(
|
||||
'tags' => 'tags',
|
||||
),
|
||||
'auto_create' => TRUE,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
}
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_taxonomy_vocabulary' => array(
|
||||
array(array(4), array('tags')),
|
||||
),
|
||||
'd6_vocabulary_field_instance' => array(
|
||||
array(array(4, 'page'), array('node', 'page', 'tags')),
|
||||
)
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_vocabulary_entity_display');
|
||||
$this->migrateTaxonomy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,11 +36,11 @@ class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testVocabularyEntityDisplay() {
|
||||
// Test that the field exists.
|
||||
$component = entity_get_display('node', 'page', 'default')->getComponent('tags');
|
||||
$component = EntityViewDisplay::load('node.page.default')->getComponent('tags');
|
||||
$this->assertIdentical('entity_reference_label', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
// Test the Id map.
|
||||
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
$this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -17,59 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
|
||||
public static $modules = ['taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'tags',
|
||||
'type' => 'entity_reference',
|
||||
'settings' => array(
|
||||
'target_type' => 'taxonomy_term',
|
||||
),
|
||||
))->save();
|
||||
|
||||
foreach (array('page', 'article', 'story') as $type) {
|
||||
entity_create('node_type', array('type' => $type))->save();
|
||||
entity_create('field_config', array(
|
||||
'label' => 'Tags',
|
||||
'description' => '',
|
||||
'field_name' => 'tags',
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $type,
|
||||
'required' => 1,
|
||||
'settings' => array(
|
||||
'handler' => 'default',
|
||||
'handler_settings' => array(
|
||||
'target_bundles' => array(
|
||||
'tags' => 'tags',
|
||||
),
|
||||
'auto_create' => TRUE,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
}
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_taxonomy_vocabulary' => array(
|
||||
array(array(4), array('tags')),
|
||||
),
|
||||
'd6_vocabulary_field_instance' => array(
|
||||
array(array(4, 'page'), array('node', 'page', 'tags')),
|
||||
)
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
$this->executeMigration('d6_vocabulary_entity_form_display');
|
||||
$this->migrateTaxonomy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,11 +36,11 @@ class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
public function testVocabularyEntityFormDisplay() {
|
||||
// Test that the field exists.
|
||||
$component = entity_get_form_display('node', 'page', 'default')->getComponent('tags');
|
||||
$component = EntityFormDisplay::load('node.page.default')->getComponent('tags');
|
||||
$this->assertIdentical('options_select', $component['type']);
|
||||
$this->assertIdentical(20, $component['weight']);
|
||||
// Test the Id map.
|
||||
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
$this->assertIdentical(array('node', 'article', 'default', 'tags'), Migration::load('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Drupal\taxonomy\Tests\Migrate\d6;
|
|||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -19,56 +20,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array('node', 'field', 'taxonomy', 'text', 'entity_reference');
|
||||
public static $modules = ['taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
entity_create('node_type', array('type' => 'page'))->save();
|
||||
entity_create('node_type', array('type' => 'article'))->save();
|
||||
entity_create('node_type', array('type' => 'story'))->save();
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_node_type' => array(
|
||||
array(array('article'), array('article')),
|
||||
array(array('page'), array('page')),
|
||||
array(array('story'), array('story')),
|
||||
),
|
||||
'd6_taxonomy_vocabulary' => array(
|
||||
array(array(4), array('tags')),
|
||||
),
|
||||
'd6_vocabulary_field' => array(
|
||||
array(array(4), array('node', 'tags')),
|
||||
)
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
// Create the vocab.
|
||||
entity_create('taxonomy_vocabulary', array(
|
||||
'field_name' => 'Test Vocabulary',
|
||||
'description' => 'Test Vocabulary',
|
||||
'vid' => 'tags',
|
||||
))->save();
|
||||
// Create the field storage.
|
||||
entity_create('field_storage_config', array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'tags',
|
||||
'type' => 'entity_reference',
|
||||
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
|
||||
'settings' => array(
|
||||
'target_type' => 'taxonomy_term',
|
||||
),
|
||||
))->save();
|
||||
|
||||
$this->executeMigration('d6_vocabulary_field_instance');
|
||||
$this->migrateTaxonomy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,10 +48,10 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
|
|||
|
||||
$settings = $field->getSettings();
|
||||
$this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
|
||||
$this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundle handler setting is correct.');
|
||||
$this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundles handler setting is correct.');
|
||||
$this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
|
||||
|
||||
$this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
$this->assertIdentical(array('node', 'article', 'tags'), Migration::load('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\taxonomy\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\migrate\Entity\Migration;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
|
@ -18,33 +19,16 @@ use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
|||
class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
|
||||
|
||||
/**
|
||||
* The modules to be enabled during the test.
|
||||
*
|
||||
* @var array
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
|
||||
public static $modules = ['taxonomy'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Add some id mappings for the dependant migrations.
|
||||
$id_mappings = array(
|
||||
'd6_taxonomy_vocabulary' => array(
|
||||
array(array(4), array('tags')),
|
||||
),
|
||||
);
|
||||
$this->prepareMigrations($id_mappings);
|
||||
|
||||
entity_create('taxonomy_vocabulary', array(
|
||||
'name' => 'Test Vocabulary',
|
||||
'description' => 'Test Vocabulary',
|
||||
'vid' => 'test_vocab',
|
||||
))->save();
|
||||
|
||||
$this->executeMigration('d6_vocabulary_field');
|
||||
$this->migrateTaxonomy();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +43,7 @@ class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
|
|||
$settings = $field_storage->getSettings();
|
||||
$this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
|
||||
|
||||
$this->assertIdentical(array('node', 'tags'), entity_load('migration', 'd6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
|
||||
$this->assertIdentical(array('node', 'tags'), Migration::load('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateNodeTaxonomyTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\FieldStorageConfigInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
/**
|
||||
* @group taxonomy
|
||||
*/
|
||||
class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = array(
|
||||
'datetime',
|
||||
'field',
|
||||
'filter',
|
||||
'image',
|
||||
'link',
|
||||
'node',
|
||||
'taxonomy',
|
||||
'telephone',
|
||||
'text',
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('node');
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->installConfig(static::$modules);
|
||||
$this->installSchema('node', ['node_access']);
|
||||
$this->installSchema('system', ['sequences']);
|
||||
|
||||
$this->executeMigration('d7_node_type');
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
'type' => 'entity_reference',
|
||||
'field_name' => 'field_tags',
|
||||
'entity_type' => 'node',
|
||||
'settings' => array(
|
||||
'target_type' => 'taxonomy_term',
|
||||
),
|
||||
'cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED,
|
||||
))->save();
|
||||
|
||||
FieldConfig::create(array(
|
||||
'entity_type' => 'node',
|
||||
'field_name' => 'field_tags',
|
||||
'bundle' => 'article',
|
||||
))->save();
|
||||
|
||||
$this->executeMigrations([
|
||||
'd7_taxonomy_vocabulary',
|
||||
'd7_taxonomy_term',
|
||||
'd7_user_role',
|
||||
'd7_user',
|
||||
'd7_node__article',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test node migration from Drupal 7 to 8.
|
||||
*/
|
||||
public function testMigration() {
|
||||
$node = Node::load(2);
|
||||
$this->assertTrue($node instanceof NodeInterface);
|
||||
$this->assertEqual(9, $node->field_tags[0]->target_id);
|
||||
$this->assertEqual(14, $node->field_tags[1]->target_id);
|
||||
$this->assertEqual(17, $node->field_tags[2]->target_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateTaxonomyTermTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\taxonomy\TermInterface;
|
||||
|
||||
/**
|
||||
* Upgrade taxonomy terms.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class MigrateTaxonomyTermTest extends MigrateDrupal7TestBase {
|
||||
|
||||
public static $modules = array('taxonomy', 'text');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installEntitySchema('taxonomy_term');
|
||||
$this->executeMigrations(['d7_taxonomy_vocabulary', 'd7_taxonomy_term']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a migrated term contains the expected values.
|
||||
*
|
||||
* @param $id
|
||||
* Entity ID to load and check.
|
||||
* @param $expected_label
|
||||
* The label the migrated entity should have.
|
||||
* @param $expected_vid
|
||||
* The parent vocabulary the migrated entity should have.
|
||||
* @param string $expected_description
|
||||
* The description the migrated entity should have.
|
||||
* @param int $expected_weight
|
||||
* The weight the migrated entity should have.
|
||||
* @param array $expected_parents
|
||||
* The parent terms the migrated entity should have.
|
||||
*/
|
||||
protected function assertEntity($id, $expected_label, $expected_vid, $expected_description = '', $expected_weight = 0, $expected_parents = []) {
|
||||
/** @var \Drupal\taxonomy\TermInterface $entity */
|
||||
$entity = Term::load($id);
|
||||
$this->assertTrue($entity instanceof TermInterface);
|
||||
$this->assertIdentical($expected_label, $entity->label());
|
||||
$this->assertIdentical($expected_vid, $entity->getVocabularyId());
|
||||
$this->assertEqual($expected_description, $entity->getDescription());
|
||||
$this->assertEqual($expected_weight, $entity->getWeight());
|
||||
$this->assertIdentical($expected_parents, $this->getParentIDs($id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 7 taxonomy term to Drupal 8 migration.
|
||||
*/
|
||||
public function testTaxonomyTerms() {
|
||||
$this->assertEntity(1, 'General discussion', 'forums', '', 2);
|
||||
$this->assertEntity(2, 'Term1', 'test_vocabulary', 'The first term.');
|
||||
$this->assertEntity(3, 'Term2', 'test_vocabulary', 'The second term.');
|
||||
$this->assertEntity(4, 'Term3', 'test_vocabulary', 'The third term.', 0, [3]);
|
||||
$this->assertEntity(5, 'Custom Forum', 'forums', 'Where the cool kids are.', 3);
|
||||
$this->assertEntity(6, 'Games', 'forums', '', 4);
|
||||
$this->assertEntity(7, 'Minecraft', 'forums', '', 1, [6]);
|
||||
$this->assertEntity(8, 'Half Life 3', 'forums', '', 0, [6]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the parent term IDs for a given term.
|
||||
*
|
||||
* @param $tid
|
||||
* ID of the term to check.
|
||||
*
|
||||
* @return array
|
||||
* List of parent term IDs.
|
||||
*/
|
||||
protected function getParentIDs($tid) {
|
||||
return array_keys(\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Migrate\d7\MigrateTaxonomyVocabularyTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
use Drupal\taxonomy\VocabularyInterface;
|
||||
|
||||
/**
|
||||
* Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class MigrateTaxonomyVocabularyTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = array('taxonomy');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('d7_taxonomy_vocabulary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a migrated vocabulary contains the expected values.
|
||||
*
|
||||
* @param $id
|
||||
* Entity ID to load and check.
|
||||
* @param $expected_label
|
||||
* The label the migrated entity should have.
|
||||
* @param $expected_description
|
||||
* The description the migrated entity should have.
|
||||
* @param $expected_hierarchy
|
||||
* The hierarchy setting the migrated entity should have.
|
||||
* @param $expected_weight
|
||||
* The weight the migrated entity should have.
|
||||
*/
|
||||
protected function assertEntity($id, $expected_label, $expected_description, $expected_hierarchy, $expected_weight) {
|
||||
/** @var \Drupal\taxonomy\VocabularyInterface $entity */
|
||||
$entity = Vocabulary::load($id);
|
||||
$this->assertTrue($entity instanceof VocabularyInterface);
|
||||
$this->assertIdentical($expected_label, $entity->label());
|
||||
$this->assertIdentical($expected_description, $entity->getDescription());
|
||||
$this->assertIdentical($expected_hierarchy, $entity->getHierarchy());
|
||||
$this->assertIdentical($expected_weight, $entity->get('weight'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the Drupal 7 taxonomy vocabularies to Drupal 8 migration.
|
||||
*/
|
||||
public function testTaxonomyVocabulary() {
|
||||
$this->assertEntity('tags', 'Tags', 'Use tags to group articles on similar topics into categories.', TAXONOMY_HIERARCHY_DISABLED, 0);
|
||||
$this->assertEntity('forums', 'Forums', 'Forum navigation vocabulary', TAXONOMY_HIERARCHY_SINGLE, -10);
|
||||
$this->assertEntity('test_vocabulary', 'Test Vocabulary', 'This is the vocabulary description', TAXONOMY_HIERARCHY_SINGLE, 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests;
|
||||
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\taxonomy\Tests;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
|
||||
|
@ -83,7 +83,7 @@ trait TaxonomyTranslationTestTrait {
|
|||
* (optional) If TRUE, create a translatable term reference field. Defaults
|
||||
* to FALSE.
|
||||
*/
|
||||
protected function setUpTermReferenceField($translatable = FALSE) {
|
||||
protected function setUpTermReferenceField() {
|
||||
$handler_settings = array(
|
||||
'target_bundles' => array(
|
||||
$this->vocabulary->id() => $this->vocabulary->id(),
|
||||
|
@ -92,7 +92,7 @@ trait TaxonomyTranslationTestTrait {
|
|||
);
|
||||
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
|
||||
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
|
||||
$field_storage->setTranslatable($translatable);
|
||||
$field_storage->setTranslatable(FALSE);
|
||||
$field_storage->save();
|
||||
|
||||
entity_get_form_display('node', 'article', 'default')
|
||||
|
|
|
@ -22,7 +22,7 @@ class TermEntityReferenceTest extends TaxonomyTestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('entity_reference', 'entity_reference_test', 'entity_test');
|
||||
public static $modules = ['entity_reference_test', 'entity_test'];
|
||||
|
||||
/**
|
||||
* Tests an entity reference field restricted to a single vocabulary.
|
||||
|
|
|
@ -50,6 +50,7 @@ class TermTest extends TaxonomyTestBase {
|
|||
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
$this->drupalPlaceBlock('local_tasks_block');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
|
||||
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'bypass node access']));
|
||||
$this->vocabulary = $this->createVocabulary();
|
||||
|
|
|
@ -50,7 +50,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
|
|||
$this->vocabulary = $this->createVocabulary();
|
||||
$this->enableTranslation();
|
||||
$this->setUpTerm();
|
||||
$this->setUpTermReferenceField(TRUE);
|
||||
$this->setUpTermReferenceField();
|
||||
$this->setUpNode();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests;
|
||||
|
||||
use Drupal\Component\Utility\Html;
|
||||
use Drupal\Component\Utility\Xss;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
|
||||
|
@ -86,13 +84,13 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
// Generate and test sanitized tokens for term1.
|
||||
$tests = array();
|
||||
$tests['[term:tid]'] = $term1->id();
|
||||
$tests['[term:name]'] = Html::escape($term1->getName());
|
||||
$tests['[term:name]'] = $term1->getName();
|
||||
$tests['[term:description]'] = $term1->description->processed;
|
||||
$tests['[term:url]'] = $term1->url('canonical', array('absolute' => TRUE));
|
||||
$tests['[term:node-count]'] = 0;
|
||||
$tests['[term:parent:name]'] = '[term:parent:name]';
|
||||
$tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
|
||||
$tests['[term:vocabulary]'] = Html::escape($this->vocabulary->label());
|
||||
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
|
||||
$tests['[term:vocabulary]'] = $this->vocabulary->label();
|
||||
|
||||
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
|
||||
|
||||
|
@ -117,14 +115,14 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
// Generate and test sanitized tokens for term2.
|
||||
$tests = array();
|
||||
$tests['[term:tid]'] = $term2->id();
|
||||
$tests['[term:name]'] = Html::escape($term2->getName());
|
||||
$tests['[term:name]'] = $term2->getName();
|
||||
$tests['[term:description]'] = $term2->description->processed;
|
||||
$tests['[term:url]'] = $term2->url('canonical', array('absolute' => TRUE));
|
||||
$tests['[term:node-count]'] = 1;
|
||||
$tests['[term:parent:name]'] = Html::escape($term1->getName());
|
||||
$tests['[term:parent:name]'] = $term1->getName();
|
||||
$tests['[term:parent:url]'] = $term1->url('canonical', array('absolute' => TRUE));
|
||||
$tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
|
||||
$tests['[term:vocabulary:name]'] = Html::escape($this->vocabulary->label());
|
||||
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
|
||||
|
||||
// Test to make sure that we generated something for each token.
|
||||
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
|
||||
|
@ -134,22 +132,11 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
// Generate and test unsanitized tokens.
|
||||
$tests['[term:name]'] = $term2->getName();
|
||||
$tests['[term:description]'] = $term2->getDescription();
|
||||
$tests['[term:parent:name]'] = $term1->getName();
|
||||
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy term token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
// Generate and test sanitized tokens.
|
||||
$tests = array();
|
||||
$tests['[vocabulary:vid]'] = $this->vocabulary->id();
|
||||
$tests['[vocabulary:name]'] = Html::escape($this->vocabulary->label());
|
||||
$tests['[vocabulary:description]'] = Xss::filter($this->vocabulary->getDescription());
|
||||
$tests['[vocabulary:name]'] = $this->vocabulary->label();
|
||||
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
|
||||
$tests['[vocabulary:node-count]'] = 1;
|
||||
$tests['[vocabulary:term-count]'] = 2;
|
||||
|
||||
|
@ -160,15 +147,6 @@ class TokenReplaceTest extends TaxonomyTestBase {
|
|||
$output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId()));
|
||||
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
|
||||
// Generate and test unsanitized tokens.
|
||||
$tests['[vocabulary:name]'] = $this->vocabulary->label();
|
||||
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
|
||||
|
||||
foreach ($tests as $input => $expected) {
|
||||
$output = $token_service->replace($input, array('vocabulary' => $this->vocabulary), array('langcode' => $language_interface->getId(), 'sanitize' => FALSE));
|
||||
$this->assertEqual($output, $expected, format_string('Unsanitized taxonomy vocabulary token %token replaced.', array('%token' => $input)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Views\ArgumentValidatorTermTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the plugin of the taxonomy: term argument validator.
|
||||
*
|
||||
* @group taxonomy
|
||||
* @see Views\taxonomy\Plugin\views\argument_validator\Term
|
||||
*/
|
||||
class ArgumentValidatorTermTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* Stores the taxonomy term used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $terms = [];
|
||||
|
||||
/**
|
||||
* Stores the taxonomy names used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $names = [];
|
||||
|
||||
/**
|
||||
* Stores the taxonomy IDs used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $ids = [];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views_test_config'];
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_argument_validator_term'];
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Add three terms to the 'tags' vocabulary.
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$this->terms[] = $term = $this->createTerm();
|
||||
$this->names[] = $term->label();
|
||||
$this->ids[] = $term->id();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the term argument validator plugin.
|
||||
*/
|
||||
public function testArgumentValidatorTerm() {
|
||||
$view = Views::getView('test_argument_validator_term');
|
||||
$view->initHandlers();
|
||||
|
||||
|
||||
// Test the single validator for term IDs.
|
||||
$view->argument['tid']->validator->options['type'] = 'tid';
|
||||
|
||||
// Pass in a single valid term.
|
||||
foreach ($this->terms as $term) {
|
||||
$this->assertTrue($view->argument['tid']->setArgument($term->id()));
|
||||
$this->assertEqual($view->argument['tid']->getTitle(), $term->label());
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
}
|
||||
|
||||
// Pass in a invalid term.
|
||||
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
|
||||
$this->assertEqual('', $view->argument['tid']->getTitle());
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
|
||||
|
||||
// Test the multiple validator for term IDs.
|
||||
$view->argument['tid']->validator->options['type'] = 'tids';
|
||||
$view->argument['tid']->options['break_phrase'] = TRUE;
|
||||
|
||||
// Pass in a single term.
|
||||
$this->assertTrue($view->argument['tid']->setArgument($this->terms[0]->id()));
|
||||
$this->assertEqual($view->argument['tid']->getTitle(), $this->terms[0]->label());
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
|
||||
// Check for multiple valid terms separated by commas.
|
||||
$this->assertTrue($view->argument['tid']->setArgument(implode(',', $this->ids)));
|
||||
$this->assertEqual($view->argument['tid']->getTitle(), implode(', ', $this->names));
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
|
||||
// Check for multiple valid terms separated by plus signs.
|
||||
$this->assertTrue($view->argument['tid']->setArgument(implode('+', $this->ids)));
|
||||
$this->assertEqual($view->argument['tid']->getTitle(), implode(' + ', $this->names));
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
|
||||
// Check for a single invalid term.
|
||||
$this->assertFalse($view->argument['tid']->setArgument(rand(1000, 10000)));
|
||||
$this->assertEqual('', $view->argument['tid']->getTitle());
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
|
||||
// Check for multiple invalid terms.
|
||||
$this->assertFalse($view->argument['tid']->setArgument(implode(',', [rand(1000, 10000), rand(1000, 10000)])));
|
||||
$this->assertEqual('', $view->argument['tid']->getTitle());
|
||||
$view->argument['tid']->validated_title = NULL;
|
||||
$view->argument['tid']->argument_validated = NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -34,7 +34,7 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
|
|||
'user',
|
||||
],
|
||||
];
|
||||
$this->assertIdentical($expected, $view->calculateDependencies());
|
||||
$this->assertIdentical($expected, $view->getDependencies());
|
||||
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
|
||||
$expected_result = array(
|
||||
array(
|
||||
|
@ -55,7 +55,7 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
|
|||
$view = Views::getView('test_taxonomy_node_term_data');
|
||||
// Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
|
||||
$expected['config'][] = 'taxonomy.vocabulary.views_testing_tags';
|
||||
$this->assertIdentical($expected, $view->calculateDependencies());
|
||||
$this->assertIdentical($expected, $view->getDependencies());
|
||||
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
|
||||
$this->assertIdenticalResultset($view, $expected_result, $column_map);
|
||||
}
|
||||
|
|
|
@ -59,4 +59,14 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
|
|||
$expected = $this->term1->id();
|
||||
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests escaping of page title when the taxonomy plugin provides it.
|
||||
*/
|
||||
public function testTermTitleEscaping() {
|
||||
$this->term1->setName('<em>Markup</em>')->save();
|
||||
$this->drupalGet('taxonomy_default_argument_test/'. $this->term1->id());
|
||||
$this->assertEscaped($this->term1->label());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
|
|||
* Tests the "all terms" field handler.
|
||||
*/
|
||||
public function testViewsHandlerAllTermsField() {
|
||||
$this->term1->setName('<em>Markup</em>')->save();
|
||||
$view = Views::getView('taxonomy_all_terms_test');
|
||||
$this->executeView($view);
|
||||
$this->drupalGet('taxonomy_all_terms_test');
|
||||
|
@ -36,6 +37,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
|
|||
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
|
||||
$this->assertEqual($actual[0]->__toString(), $this->term1->label());
|
||||
$this->assertEqual($actual[1]->__toString(), $this->term1->label());
|
||||
$this->assertEscaped($this->term1->label());
|
||||
|
||||
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
|
||||
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
@ -36,7 +36,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views', 'entity_reference');
|
||||
public static $modules = ['node', 'taxonomy', 'taxonomy_test_views'];
|
||||
|
||||
/**
|
||||
* A nested array of \Drupal\taxonomy\TermInterface objects.
|
||||
|
@ -121,7 +121,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
|
|||
'user',
|
||||
],
|
||||
];
|
||||
$this->assertIdentical($expected, $view->calculateDependencies());
|
||||
$this->assertIdentical($expected, $view->calculateDependencies()->getDependencies());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyTermArgumentDepthTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
/**
|
||||
* Tests the taxonomy term with depth argument.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class TaxonomyTermArgumentDepthTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $testViews = ['test_argument_taxonomy_index_tid_depth'];
|
||||
|
||||
/**
|
||||
* @var \Drupal\taxonomy\TermInterface[]
|
||||
*/
|
||||
protected $terms = [];
|
||||
|
||||
/**
|
||||
* @var \Drupal\views\ViewExecutable
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
// Create a term with markup in the label.
|
||||
$first = $this->createTerm(['name' => '<em>First</em>']);
|
||||
|
||||
// Create a node w/o any terms.
|
||||
$settings = ['type' => 'article'];
|
||||
|
||||
// Create a node with linked to the term.
|
||||
$settings['field_views_testing_tags'][0]['target_id'] = $first->id();
|
||||
$this->nodes[] = $this->drupalCreateNode($settings);
|
||||
|
||||
$this->terms[0] = $first;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests title escaping.
|
||||
*/
|
||||
public function testTermWithDepthArgumentTitleEscaping() {
|
||||
$this->drupalGet('test_argument_taxonomy_index_tid_depth/' . $this->terms[0]->id());
|
||||
$this->assertEscaped($this->terms[0]->label());
|
||||
}
|
||||
|
||||
}
|
|
@ -9,7 +9,7 @@ namespace Drupal\taxonomy\Tests\Views;
|
|||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\views\Tests\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
||||
|
|
|
@ -142,37 +142,6 @@ class VocabularyCrudTest extends TaxonomyTestBase {
|
|||
$this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that machine name changes are properly reflected.
|
||||
*/
|
||||
function testTaxonomyVocabularyChangeMachineName() {
|
||||
// Add a field to the vocabulary.
|
||||
entity_create('field_storage_config', array(
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'type' => 'test_field',
|
||||
))->save();
|
||||
entity_create('field_config', array(
|
||||
'field_name' => 'field_test',
|
||||
'entity_type' => 'taxonomy_term',
|
||||
'bundle' => $this->vocabulary->id(),
|
||||
))->save();
|
||||
|
||||
// Change the machine name.
|
||||
$old_name = $this->vocabulary->id();
|
||||
$new_name = Unicode::strtolower($this->randomMachineName());
|
||||
$this->vocabulary->set('vid', $new_name);
|
||||
$this->vocabulary->save();
|
||||
|
||||
// Check that entity bundles are properly updated.
|
||||
$info = entity_get_bundles('taxonomy_term');
|
||||
$this->assertFalse(isset($info[$old_name]), 'The old bundle name does not appear in entity_get_bundles().');
|
||||
$this->assertTrue(isset($info[$new_name]), 'The new bundle name appears in entity_get_bundles().');
|
||||
|
||||
// Check that the field is still attached to the vocabulary.
|
||||
$this->assertTrue(FieldConfig::loadByName('taxonomy_term', $new_name, 'field_test'), 'The bundle name was updated correctly.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test uninstall and reinstall of the taxonomy module.
|
||||
*/
|
||||
|
|
|
@ -14,6 +14,12 @@ namespace Drupal\taxonomy\Tests;
|
|||
*/
|
||||
class VocabularyPermissionsTest extends TaxonomyTestBase {
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, edit and delete a taxonomy term via the user interface.
|
||||
*/
|
||||
|
|
|
@ -30,6 +30,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
|
|||
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
|
||||
$this->vocabulary = $this->createVocabulary();
|
||||
$this->drupalPlaceBlock('local_actions_block');
|
||||
$this->drupalPlaceBlock('page_title_block');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,18 +7,17 @@
|
|||
|
||||
namespace Drupal\taxonomy;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Entity\BundleEntityFormBase;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\taxonomy\VocabularyStorageInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Base form for vocabulary edit forms.
|
||||
*/
|
||||
class VocabularyForm extends EntityForm {
|
||||
class VocabularyForm extends BundleEntityFormBase {
|
||||
|
||||
/**
|
||||
* The vocabulary storage.
|
||||
|
@ -112,7 +111,8 @@ class VocabularyForm extends EntityForm {
|
|||
'#value' => '0',
|
||||
);
|
||||
|
||||
return parent::form($form, $form_state, $vocabulary);
|
||||
$form = parent::form($form, $form_state);
|
||||
return $this->protectBundleIdElement($form);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,14 +147,14 @@ class VocabularyForm extends EntityForm {
|
|||
/**
|
||||
* Determines if the vocabulary already exists.
|
||||
*
|
||||
* @param string $id
|
||||
* The vocabulary ID
|
||||
* @param string $vid
|
||||
* The vocabulary ID.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the vocabulary exists, FALSE otherwise.
|
||||
*/
|
||||
public function exists($id) {
|
||||
$action = $this->vocabularyStorage->load($id);
|
||||
public function exists($vid) {
|
||||
$action = $this->vocabularyStorage->load($vid);
|
||||
return !empty($action);
|
||||
}
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
|
|||
unset($this->weightKey);
|
||||
}
|
||||
$build = parent::render();
|
||||
$build['table']['#empty'] = t('No vocabularies available. <a href="@link">Add vocabulary</a>.', array('@link' => \Drupal::url('entity.taxonomy_vocabulary.add_form')));
|
||||
$build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', array(':link' => \Drupal::url('entity.taxonomy_vocabulary.add_form')));
|
||||
return $build;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue