Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -22,7 +22,7 @@ class TaxonomyController extends ControllerBase {
* The taxonomy term add form.
*/
public function addForm(VocabularyInterface $taxonomy_vocabulary) {
$term = $this->entityManager()->getStorage('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id()));
$term = $this->entityManager()->getStorage('taxonomy_term')->create(['vid' => $taxonomy_vocabulary->id()]);
return $this->entityFormBuilder()->getForm($term);
}

View file

@ -61,14 +61,14 @@ class Term extends ContentEntityBase implements TermInterface {
parent::postDelete($storage, $entities);
// See if any of the term's children are about to be become orphans.
$orphans = array();
$orphans = [];
foreach (array_keys($entities) as $tid) {
if ($children = $storage->loadChildren($tid)) {
foreach ($children as $child) {
// If the term has multiple parents, we don't delete it.
$parents = $storage->loadParents($child->id());
if (empty($parents)) {
$orphans[] = $child->id();
$orphans[] = $child;
}
}
}
@ -79,7 +79,7 @@ class Term extends ContentEntityBase implements TermInterface {
$storage->deleteTermHierarchy(array_keys($entities));
if (!empty($orphans)) {
entity_delete_multiple('taxonomy_term', $orphans);
$storage->delete($orphans);
}
}
@ -92,7 +92,7 @@ class Term extends ContentEntityBase implements TermInterface {
// Only change the parents if a value is set, keep the existing values if
// not.
if (isset($this->parent->target_id)) {
$storage->deleteTermHierarchy(array($this->id()));
$storage->deleteTermHierarchy([$this->id()]);
$storage->updateTermHierarchy($this);
}
}
@ -116,35 +116,33 @@ class Term extends ContentEntityBase implements TermInterface {
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The term name.'))
->setTranslatable(TRUE)
->setRequired(TRUE)
->setSetting('max_length', 255)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'string',
'weight' => -5,
))
->setDisplayOptions('form', array(
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -5,
))
])
->setDisplayConfigurable('form', TRUE);
$fields['description'] = BaseFieldDefinition::create('text_long')
->setLabel(t('Description'))
->setDescription(t('A description of the term.'))
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'text_default',
'weight' => 0,
))
])
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('form', array(
->setDisplayOptions('form', [
'type' => 'text_textfield',
'weight' => 0,
))
])
->setDisplayConfigurable('form', TRUE);
$fields['weight'] = BaseFieldDefinition::create('integer')
@ -234,4 +232,17 @@ class Term extends ContentEntityBase implements TermInterface {
return $this->get('vid')->target_id;
}
/**
* {@inheritdoc}
*/
protected function getFieldsToSkipFromTranslationChangesCheck() {
// @todo the current implementation of the parent field makes it impossible
// for ::hasTranslationChanges() to correctly check the field for changes,
// so it is currently skipped from the comparision and has to be fixed by
// https://www.drupal.org/node/2843060.
$fields = parent::getFieldsToSkipFromTranslationChangesCheck();
$fields[] = 'parent';
return $fields;
}
}

View file

@ -140,13 +140,13 @@ class Vocabulary extends ConfigEntityBundleBase implements VocabularyInterface {
return;
}
$vocabularies = array();
$vocabularies = [];
foreach ($entities as $vocabulary) {
$vocabularies[$vocabulary->id()] = $vocabulary->id();
}
// Load all Taxonomy module fields and delete those which use only this
// vocabulary.
$field_storages = entity_load_multiple_by_properties('field_storage_config', array('module' => 'taxonomy'));
$field_storages = entity_load_multiple_by_properties('field_storage_config', ['module' => 'taxonomy']);
foreach ($field_storages as $field_storage) {
$modified_storage = FALSE;
// Term reference fields may reference terms from more than one

View file

@ -21,6 +21,13 @@ class OverviewTerms extends FormBase {
*/
protected $moduleHandler;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The term storage handler.
*
@ -38,6 +45,7 @@ class OverviewTerms extends FormBase {
*/
public function __construct(ModuleHandlerInterface $module_handler, EntityManagerInterface $entity_manager) {
$this->moduleHandler = $module_handler;
$this->entityManager = $entity_manager;
$this->storageController = $entity_manager->getStorage('taxonomy_term');
}
@ -101,10 +109,10 @@ class OverviewTerms extends FormBase {
$forward_step = 0;
// An array of the terms to be displayed on this page.
$current_page = array();
$current_page = [];
$delta = 0;
$term_deltas = array();
$term_deltas = [];
$tree = $this->storageController->loadTree($taxonomy_vocabulary->id(), 0, NULL, TRUE);
$tree_index = 0;
do {
@ -199,93 +207,94 @@ class OverviewTerms extends FormBase {
$destination = $this->getDestinationArray();
$row_position = 0;
// Build the actual form.
$form['terms'] = array(
$form['terms'] = [
'#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())))),
'#attributes' => array(
'#header' => [$this->t('Name'), $this->t('Weight'), $this->t('Operations')],
'#empty' => $this->t('No terms available. <a href=":link">Add term</a>.', [':link' => $this->url('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $taxonomy_vocabulary->id()])]),
'#attributes' => [
'id' => 'taxonomy',
),
);
],
];
foreach ($current_page as $key => $term) {
/** @var $term \Drupal\Core\Entity\EntityInterface */
$term = $this->entityManager->getTranslationFromContext($term);
$form['terms'][$key]['#term'] = $term;
$indentation = array();
$indentation = [];
if (isset($term->depth) && $term->depth > 0) {
$indentation = array(
$indentation = [
'#theme' => 'indentation',
'#size' => $term->depth,
);
];
}
$form['terms'][$key]['term'] = array(
$form['terms'][$key]['term'] = [
'#prefix' => !empty($indentation) ? drupal_render($indentation) : '',
'#type' => 'link',
'#title' => $term->getName(),
'#url' => $term->urlInfo(),
);
];
if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) {
$parent_fields = TRUE;
$form['terms'][$key]['term']['tid'] = array(
$form['terms'][$key]['term']['tid'] = [
'#type' => 'hidden',
'#value' => $term->id(),
'#attributes' => array(
'class' => array('term-id'),
),
);
$form['terms'][$key]['term']['parent'] = array(
'#attributes' => [
'class' => ['term-id'],
],
];
$form['terms'][$key]['term']['parent'] = [
'#type' => 'hidden',
// Yes, default_value on a hidden. It needs to be changeable by the
// javascript.
'#default_value' => $term->parents[0],
'#attributes' => array(
'class' => array('term-parent'),
),
);
$form['terms'][$key]['term']['depth'] = array(
'#attributes' => [
'class' => ['term-parent'],
],
];
$form['terms'][$key]['term']['depth'] = [
'#type' => 'hidden',
// Same as above, the depth is modified by javascript, so it's a
// default_value.
'#default_value' => $term->depth,
'#attributes' => array(
'class' => array('term-depth'),
),
);
'#attributes' => [
'class' => ['term-depth'],
],
];
}
$form['terms'][$key]['weight'] = array(
$form['terms'][$key]['weight'] = [
'#type' => 'weight',
'#delta' => $delta,
'#title' => $this->t('Weight for added term'),
'#title_display' => 'invisible',
'#default_value' => $term->getWeight(),
'#attributes' => array(
'class' => array('term-weight'),
),
);
$operations = array(
'edit' => array(
'#attributes' => [
'class' => ['term-weight'],
],
];
$operations = [
'edit' => [
'title' => $this->t('Edit'),
'query' => $destination,
'url' => $term->urlInfo('edit-form'),
),
'delete' => array(
],
'delete' => [
'title' => $this->t('Delete'),
'query' => $destination,
'url' => $term->urlInfo('delete-form'),
),
);
],
];
if ($this->moduleHandler->moduleExists('content_translation') && content_translation_translate_access($term)->isAllowed()) {
$operations['translate'] = array(
$operations['translate'] = [
'title' => $this->t('Translate'),
'query' => $destination,
'url' => $term->urlInfo('drupal:content-translation-overview'),
);
];
}
$form['terms'][$key]['operations'] = array(
$form['terms'][$key]['operations'] = [
'#type' => 'operations',
'#links' => $operations,
);
];
$form['terms'][$key]['#attributes']['class'] = array();
$form['terms'][$key]['#attributes']['class'] = [];
if ($parent_fields) {
$form['terms'][$key]['#attributes']['class'][] = 'draggable';
}
@ -314,44 +323,44 @@ class OverviewTerms extends FormBase {
}
if ($parent_fields) {
$form['terms']['#tabledrag'][] = array(
$form['terms']['#tabledrag'][] = [
'action' => 'match',
'relationship' => 'parent',
'group' => 'term-parent',
'subgroup' => 'term-parent',
'source' => 'term-id',
'hidden' => FALSE,
);
$form['terms']['#tabledrag'][] = array(
];
$form['terms']['#tabledrag'][] = [
'action' => 'depth',
'relationship' => 'group',
'group' => 'term-depth',
'hidden' => FALSE,
);
];
$form['terms']['#attached']['library'][] = 'taxonomy/drupal.taxonomy';
$form['terms']['#attached']['drupalSettings']['taxonomy'] = [
'backStep' => $back_step,
'forwardStep' => $forward_step,
];
}
$form['terms']['#tabledrag'][] = array(
$form['terms']['#tabledrag'][] = [
'action' => 'order',
'relationship' => 'sibling',
'group' => 'term-weight',
);
];
if ($taxonomy_vocabulary->getHierarchy() != VocabularyInterface::HIERARCHY_MULTIPLE && count($tree) > 1) {
$form['actions'] = array('#type' => 'actions', '#tree' => FALSE);
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions', '#tree' => FALSE];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Save'),
'#button_type' => 'primary',
);
$form['actions']['reset_alphabetical'] = array(
];
$form['actions']['reset_alphabetical'] = [
'#type' => 'submit',
'#submit' => array('::submitReset'),
'#submit' => ['::submitReset'],
'#value' => $this->t('Reset to alphabetical'),
);
];
}
$form['pager_pager'] = ['#type' => 'pager'];
@ -378,13 +387,13 @@ class OverviewTerms extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Sort term order based on weight.
uasort($form_state->getValue('terms'), array('Drupal\Component\Utility\SortArray', 'sortByWeightElement'));
uasort($form_state->getValue('terms'), ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
$vocabulary = $form_state->get(['taxonomy', 'vocabulary']);
// Update the current hierarchy type as we go.
$hierarchy = VocabularyInterface::HIERARCHY_DISABLED;
$changed_terms = array();
$changed_terms = [];
$tree = $this->storageController->loadTree($vocabulary->id(), 0, NULL, TRUE);
if (empty($tree)) {
@ -405,7 +414,7 @@ class OverviewTerms extends FormBase {
}
// Renumber the current page weights and assign any new parents.
$level_weights = array();
$level_weights = [];
foreach ($form_state->getValue('terms') as $tid => $values) {
if (isset($form['terms'][$tid]['#term'])) {
$term = $form['terms'][$tid]['#term'];

View file

@ -38,7 +38,7 @@ class TermDeleteForm extends ContentEntityDeleteForm {
* {@inheritdoc}
*/
protected function getDeletionMessage() {
return $this->t('Deleted term %name.', array('%name' => $this->entity->label()));
return $this->t('Deleted term %name.', ['%name' => $this->entity->label()]);
}
/**
@ -54,7 +54,7 @@ class TermDeleteForm extends ContentEntityDeleteForm {
$vocabulary = $storage->load($this->entity->bundle());
// @todo Move to storage http://drupal.org/node/1988712
taxonomy_check_vocabulary_hierarchy($vocabulary, array('tid' => $term->id()));
taxonomy_check_vocabulary_hierarchy($vocabulary, ['tid' => $term->id()]);
}
}

View file

@ -20,7 +20,7 @@ class VocabularyDeleteForm extends EntityDeleteForm {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the vocabulary %title?', array('%title' => $this->entity->label()));
return $this->t('Are you sure you want to delete the vocabulary %title?', ['%title' => $this->entity->label()]);
}
/**
@ -34,7 +34,7 @@ class VocabularyDeleteForm extends EntityDeleteForm {
* {@inheritdoc}
*/
protected function getDeletionMessage() {
return $this->t('Deleted vocabulary %name.', array('%name' => $this->entity->label()));
return $this->t('Deleted vocabulary %name.', ['%name' => $this->entity->label()]);
}
}

View file

@ -49,7 +49,7 @@ class VocabularyResetForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', array('%title' => $this->entity->label()));
return $this->t('Are you sure you want to reset the vocabulary %title to alphabetical order?', ['%title' => $this->entity->label()]);
}
/**
@ -80,8 +80,8 @@ class VocabularyResetForm extends EntityConfirmFormBase {
parent::submitForm($form, $form_state);
$this->termStorage->resetWeights($this->entity->id());
drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label())));
$this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', array('%name' => $this->entity->label()));
drupal_set_message($this->t('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]));
$this->logger('taxonomy')->notice('Reset vocabulary %name to alphabetical order.', ['%name' => $this->entity->label()]);
$form_state->setRedirectUrl($this->getCancelUrl());
}

View file

@ -53,7 +53,7 @@ class TermSelection extends DefaultSelection {
return parent::getReferenceableEntities($match, $match_operator, $limit);
}
$options = array();
$options = [];
$bundles = $this->entityManager->getBundleInfo('taxonomy_term');
$handler_settings = $this->configuration['handler_settings'];

View file

@ -25,16 +25,16 @@ class EntityReferenceTaxonomyTermRssFormatter extends EntityReferenceFormatterBa
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$parent_entity = $items->getEntity();
$elements = array();
$elements = [];
foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
$parent_entity->rss_elements[] = array(
$parent_entity->rss_elements[] = [
'key' => 'category',
'value' => $entity->label(),
'attributes' => array(
'domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], array('absolute' => TRUE)) : '',
),
);
'attributes' => [
'domain' => $entity->id() ? \Drupal::url('entity.taxonomy_term.canonical', ['taxonomy_term' => $entity->id()], ['absolute' => TRUE]) : '',
],
];
}
return $elements;

View file

@ -7,7 +7,6 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\Migration;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\Plugin\MigrateCckFieldPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -84,8 +83,19 @@ class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInter
// we'll create a migration just for the node properties.
}
$vocabulary_source_plugin = static::getSourcePlugin('d7_taxonomy_vocabulary');
try {
foreach (static::getSourcePlugin('d7_taxonomy_vocabulary') as $row) {
$vocabulary_source_plugin->checkRequirements();
}
catch (RequirementsException $e) {
// If the d7_taxonomy_vocabulary requirements failed, that means we do not
// have a Drupal source database configured - there is nothing to
// generate.
return $this->derivatives;
}
try {
foreach ($vocabulary_source_plugin as $row) {
$bundle = $row->getSourceProperty('machine_name');
$values = $base_plugin_definition;

View file

@ -20,20 +20,20 @@ class TaxonomyTermReference extends CckFieldPluginBase {
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return array();
return [];
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = array(
$process = [
'plugin' => 'iterator',
'source' => $field_name,
'process' => array(
'process' => [
'target_id' => 'tid',
),
);
],
];
$migration->setProcessOfProperty($field_name, $process);
}

View file

@ -64,14 +64,14 @@ class Term extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
$fields = array(
$fields = [
'tid' => $this->t('The term ID.'),
'vid' => $this->t('Existing term VID'),
'name' => $this->t('The name of the term.'),
'description' => $this->t('The term description.'),
'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.');
}
@ -84,7 +84,7 @@ class Term extends DrupalSqlBase {
public function prepareRow(Row $row) {
// Find parents for this row.
$parents = $this->select($this->termHierarchyTable, 'th')
->fields('th', array('parent', 'tid'))
->fields('th', ['parent', 'tid'])
->condition('tid', $row->getSourceProperty('tid'))
->execute()
->fetchCol();

View file

@ -26,10 +26,10 @@ class TermNode extends DrupalSqlBase {
public function query() {
$query = $this->select('term_node', 'tn')
->distinct()
->fields('tn', array('nid', 'vid'))
->fields('n', array('type'));
->fields('tn', ['nid', 'vid'])
->fields('n', ['type']);
// Because this is an inner join it enforces the current revision.
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', array(':vid' => $this->configuration['vid']));
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]);
$query->innerJoin('node', 'n', static::JOIN);
return $query;
}
@ -38,11 +38,11 @@ class TermNode extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'nid' => $this->t('The node revision ID.'),
'vid' => $this->t('The node revision ID.'),
'tid' => $this->t('The term ID.'),
);
];
}
/**
@ -51,10 +51,10 @@ class TermNode extends DrupalSqlBase {
public function prepareRow(Row $row) {
// Select the terms belonging to the revision selected.
$query = $this->select('term_node', 'tn')
->fields('tn', array('tid'))
->fields('tn', ['tid'])
->condition('n.nid', $row->getSourceProperty('nid'));
$query->join('node', 'n', static::JOIN);
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', array(':vid' => $this->configuration['vid']));
$query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]);
$row->setSourceProperty('tid', $query->execute()->fetchCol());
return parent::prepareRow($row);
}

View file

@ -21,7 +21,7 @@ class Vocabulary extends DrupalSqlBase {
*/
public function query() {
$query = $this->select('vocabulary', 'v')
->fields('v', array(
->fields('v', [
'vid',
'name',
'description',
@ -33,7 +33,7 @@ class Vocabulary extends DrupalSqlBase {
'tags',
'module',
'weight',
));
]);
return $query;
}
@ -41,7 +41,7 @@ class Vocabulary extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'vid' => $this->t('The vocabulary ID.'),
'name' => $this->t('The name of the vocabulary.'),
'description' => $this->t('The description of the vocabulary.'),
@ -54,7 +54,7 @@ class Vocabulary extends DrupalSqlBase {
'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.'),
);
];
}
/**
@ -63,7 +63,7 @@ class Vocabulary extends DrupalSqlBase {
public function prepareRow(Row $row) {
// Find node types for this row.
$node_types = $this->select('vocabulary_node_types', 'nt')
->fields('nt', array('type', 'vid'))
->fields('nt', ['type', 'vid'])
->condition('vid', $row->getSourceProperty('vid'))
->execute()
->fetchCol();

View file

@ -18,7 +18,7 @@ class VocabularyPerType extends Vocabulary {
public function query() {
$query = parent::query();
$query->join('vocabulary_node_types', 'nt', 'v.vid = nt.vid');
$query->fields('nt', array('type'));
$query->fields('nt', ['type']);
return $query;
}

View file

@ -19,7 +19,7 @@ class Vocabulary extends DrupalSqlBase {
*/
public function query() {
$query = $this->select('taxonomy_vocabulary', 'v')
->fields('v', array(
->fields('v', [
'vid',
'name',
'description',
@ -27,7 +27,7 @@ class Vocabulary extends DrupalSqlBase {
'module',
'weight',
'machine_name',
));
]);
return $query;
}
@ -35,7 +35,7 @@ class Vocabulary extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'vid' => $this->t('The vocabulary ID.'),
'name' => $this->t('The name of the vocabulary.'),
'description' => $this->t('The description of the vocabulary.'),
@ -43,7 +43,7 @@ class Vocabulary extends DrupalSqlBase {
'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 machine name of the vocabulary.')
);
];
}
/**

View file

@ -15,7 +15,7 @@ use Drupal\views\Plugin\views\argument\ManyToOne;
class IndexTid extends ManyToOne {
public function titleQuery() {
$titles = array();
$titles = [];
$terms = Term::loadMultiple($this->value);
foreach ($terms as $term) {
$titles[] = \Drupal::entityManager()->getTranslationFromContext($term)->label();

View file

@ -44,27 +44,27 @@ class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPlugin
protected function defineOptions() {
$options = parent::defineOptions();
$options['depth'] = array('default' => 0);
$options['break_phrase'] = array('default' => FALSE);
$options['use_taxonomy_term_path'] = array('default' => FALSE);
$options['depth'] = ['default' => 0];
$options['break_phrase'] = ['default' => FALSE];
$options['use_taxonomy_term_path'] = ['default' => FALSE];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['depth'] = array(
$form['depth'] = [
'#type' => 'weight',
'#title' => $this->t('Depth'),
'#default_value' => $this->options['depth'],
'#description' => $this->t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'),
);
];
$form['break_phrase'] = array(
$form['break_phrase'] = [
'#type' => 'checkbox',
'#title' => $this->t('Allow multiple values'),
'#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3. Due to the number of JOINs it would require, AND will be treated as OR with this filter.'),
'#default_value' => !empty($this->options['break_phrase']),
);
];
parent::buildOptionsForm($form, $form_state);
}
@ -74,7 +74,7 @@ class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPlugin
*/
protected function defaultActions($which = NULL) {
if ($which) {
if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) {
if (in_array($which, ['ignore', 'not found', 'empty', 'default'])) {
return parent::defaultActions($which);
}
return;
@ -92,7 +92,7 @@ class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPlugin
if (!empty($this->options['break_phrase'])) {
$break = static::breakString($this->argument);
if ($break->value === array(-1)) {
if ($break->value === [-1]) {
return FALSE;
}
@ -130,7 +130,7 @@ class IndexTidDepth extends ArgumentPluginBase implements ContainerFactoryPlugin
$this->query->addWhere(0, "$this->tableAlias.$this->realField", $subquery, 'IN');
}
function title() {
public function title() {
$term = $this->termStorage->load($this->argument);
if (!empty($term)) {
return $term->getName();

View file

@ -45,7 +45,7 @@ class Taxonomy extends NumericArgument implements ContainerFactoryPluginInterfac
/**
* Override the behavior of title(). Get the title of the node.
*/
function title() {
public function title() {
// There might be no valid argument.
if ($this->argument) {
$term = $this->termStorage->load($this->argument);

View file

@ -54,7 +54,7 @@ class VocabularyVid extends NumericArgument {
/**
* Override the behavior of title(). Get the name of the vocabulary.
*/
function title() {
public function title() {
$vocabulary = $this->vocabularyStorage->load($this->argument);
if ($vocabulary) {
return $vocabulary->label();

View file

@ -96,11 +96,11 @@ class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
protected function defineOptions() {
$options = parent::defineOptions();
$options['term_page'] = array('default' => TRUE);
$options['node'] = array('default' => FALSE);
$options['anyall'] = array('default' => ',');
$options['limit'] = array('default' => FALSE);
$options['vids'] = array('default' => array());
$options['term_page'] = ['default' => TRUE];
$options['node'] = ['default' => FALSE];
$options['anyall'] = ['default' => ','];
$options['limit'] = ['default' => FALSE];
$options['vids'] = ['default' => []];
return $options;
}
@ -109,67 +109,67 @@ class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['term_page'] = array(
$form['term_page'] = [
'#type' => 'checkbox',
'#title' => $this->t('Load default filter from term page'),
'#default_value' => $this->options['term_page'],
);
$form['node'] = array(
];
$form['node'] = [
'#type' => 'checkbox',
'#title' => $this->t('Load default filter from node page, that\'s good for related taxonomy blocks'),
'#default_value' => $this->options['node'],
);
];
$form['limit'] = array(
$form['limit'] = [
'#type' => 'checkbox',
'#title' => $this->t('Limit terms by vocabulary'),
'#default_value' => $this->options['limit'],
'#states' => array(
'visible' => array(
':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="options[argument_default][taxonomy_tid][node]"]' => ['checked' => TRUE],
],
],
];
$options = array();
$options = [];
$vocabularies = $this->vocabularyStorage->loadMultiple();
foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label();
}
$form['vids'] = array(
$form['vids'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Vocabularies'),
'#options' => $options,
'#default_value' => $this->options['vids'],
'#states' => array(
'visible' => array(
':input[name="options[argument_default][taxonomy_tid][limit]"]' => array('checked' => TRUE),
':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE),
),
),
);
'#states' => [
'visible' => [
':input[name="options[argument_default][taxonomy_tid][limit]"]' => ['checked' => TRUE],
':input[name="options[argument_default][taxonomy_tid][node]"]' => ['checked' => TRUE],
],
],
];
$form['anyall'] = array(
$form['anyall'] = [
'#type' => 'radios',
'#title' => $this->t('Multiple-value handling'),
'#default_value' => $this->options['anyall'],
'#options' => array(
'#options' => [
',' => $this->t('Filter to items that share all terms'),
'+' => $this->t('Filter to items that share any term'),
),
'#states' => array(
'visible' => array(
':input[name="options[argument_default][taxonomy_tid][node]"]' => array('checked' => TRUE),
),
),
);
],
'#states' => [
'visible' => [
':input[name="options[argument_default][taxonomy_tid][node]"]' => ['checked' => TRUE],
],
],
];
}
/**
* {@inheritdoc}
*/
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = array()) {
public function submitOptionsForm(&$form, FormStateInterface $form_state, &$options = []) {
// Filter unselected items so we don't unnecessarily store giant arrays.
$options['vids'] = array_filter($options['vids']);
}
@ -188,7 +188,7 @@ class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
if (!empty($this->options['node'])) {
// Just check, if a node could be detected.
if (($node = $this->routeMatch->getParameter('node')) && $node instanceof NodeInterface) {
$taxonomy = array();
$taxonomy = [];
foreach ($node->getFieldDefinitions() as $field) {
if ($field->getType() == 'entity_reference' && $field->getSetting('target_type') == 'taxonomy_term') {
$taxonomy_terms = $node->{$field->getName()}->referencedEntities();
@ -199,7 +199,7 @@ class Tid extends ArgumentDefaultPluginBase implements CacheableDependencyInterf
}
}
if (!empty($this->options['limit'])) {
$tids = array();
$tids = [];
// filter by vocabulary
foreach ($taxonomy as $tid => $vocab) {
if (!empty($this->options['vids'][$vocab])) {

View file

@ -39,7 +39,7 @@ class TermName extends Entity {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['transform'] = array('default' => FALSE);
$options['transform'] = ['default' => FALSE];
return $options;
}
@ -50,11 +50,11 @@ class TermName extends Entity {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['transform'] = array(
$form['transform'] = [
'#type' => 'checkbox',
'#title' => $this->t('Transform dashes in URL to spaces in term name filter values'),
'#default_value' => $this->options['transform'],
);
];
}
/**
@ -64,7 +64,7 @@ class TermName extends Entity {
if ($this->options['transform']) {
$argument = str_replace('-', ' ', $argument);
}
$terms = $this->termStorage->loadByProperties(array('name' => $argument));
$terms = $this->termStorage->loadByProperties(['name' => $argument]);
if (!$terms) {
// Returned empty array no terms with the name.

View file

@ -62,19 +62,19 @@ class TaxonomyIndexTid extends PrerenderList {
// @todo: Wouldn't it be possible to use $this->base_table and no if here?
if ($view->storage->get('base_table') == 'node_field_revision') {
$this->additional_fields['nid'] = array('table' => 'node_field_revision', 'field' => 'nid');
$this->additional_fields['nid'] = ['table' => 'node_field_revision', 'field' => 'nid'];
}
else {
$this->additional_fields['nid'] = array('table' => 'node_field_data', 'field' => 'nid');
$this->additional_fields['nid'] = ['table' => 'node_field_data', 'field' => 'nid'];
}
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['link_to_taxonomy'] = array('default' => TRUE);
$options['limit'] = array('default' => FALSE);
$options['vids'] = array('default' => array());
$options['link_to_taxonomy'] = ['default' => TRUE];
$options['limit'] = ['default' => FALSE];
$options['vids'] = ['default' => []];
return $options;
}
@ -83,36 +83,36 @@ class TaxonomyIndexTid extends PrerenderList {
* Provide "link to term" option.
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['link_to_taxonomy'] = array(
$form['link_to_taxonomy'] = [
'#title' => $this->t('Link this field to its term page'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_taxonomy']),
);
];
$form['limit'] = array(
$form['limit'] = [
'#type' => 'checkbox',
'#title' => $this->t('Limit terms by vocabulary'),
'#default_value' => $this->options['limit'],
);
];
$options = array();
$options = [];
$vocabularies = $this->vocabularyStorage->loadMultiple();
foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label();
}
$form['vids'] = array(
$form['vids'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Vocabularies'),
'#options' => $options,
'#default_value' => $this->options['vids'],
'#states' => array(
'visible' => array(
':input[name="options[limit]"]' => array('checked' => TRUE),
),
),
'#states' => [
'visible' => [
':input[name="options[limit]"]' => ['checked' => TRUE],
],
],
);
];
parent::buildOptionsForm($form, $form_state);
}
@ -127,7 +127,7 @@ class TaxonomyIndexTid extends PrerenderList {
public function preRender(&$values) {
$vocabularies = $this->vocabularyStorage->loadMultiple();
$this->field_alias = $this->aliases['nid'];
$nids = array();
$nids = [];
foreach ($values as $result) {
if (!empty($result->{$this->aliases['nid']})) {
$nids[] = $result->{$this->aliases['nid']};
@ -137,7 +137,7 @@ class TaxonomyIndexTid extends PrerenderList {
if ($nids) {
$vocabs = array_filter($this->options['vids']);
if (empty($this->options['limit'])) {
$vocabs = array();
$vocabs = [];
}
$result = \Drupal::entityManager()->getStorage('taxonomy_term')->getNodeTerms($nids, $vocabs);
@ -157,7 +157,7 @@ class TaxonomyIndexTid extends PrerenderList {
}
}
function render_item($count, $item) {
public function render_item($count, $item) {
return $item['name'];
}
@ -169,7 +169,7 @@ class TaxonomyIndexTid extends PrerenderList {
}
protected function addSelfTokens(&$tokens, $item) {
foreach (array('tid', 'name', 'vocabulary_vid', 'vocabulary') as $token) {
foreach (['tid', 'name', 'vocabulary_vid', 'vocabulary'] as $token) {
$tokens['{{ ' . $this->options['id'] . '__' . $token . ' }}'] = isset($item[$token]) ? $item[$token] : '';
}
}

View file

@ -3,7 +3,7 @@
namespace Drupal\taxonomy\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\Field;
use Drupal\views\Plugin\views\field\EntityField;
use Drupal\views\ResultRow;
/**
@ -13,7 +13,7 @@ use Drupal\views\ResultRow;
*
* @ViewsField("term_name")
*/
class TermName extends Field {
class TermName extends EntityField {
/**
* {@inheritdoc}
@ -37,7 +37,7 @@ class TermName extends Field {
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['convert_spaces'] = array('default' => FALSE);
$options['convert_spaces'] = ['default' => FALSE];
return $options;
}
@ -45,11 +45,11 @@ class TermName extends Field {
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['convert_spaces'] = array(
$form['convert_spaces'] = [
'#title' => $this->t('Convert spaces in term names to hyphens'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['convert_spaces']),
);
];
parent::buildOptionsForm($form, $form_state);
}

View file

@ -94,18 +94,18 @@ class TaxonomyIndexTid extends ManyToOne {
protected function defineOptions() {
$options = parent::defineOptions();
$options['type'] = array('default' => 'textfield');
$options['limit'] = array('default' => TRUE);
$options['vid'] = array('default' => '');
$options['hierarchy'] = array('default' => FALSE);
$options['error_message'] = array('default' => TRUE);
$options['type'] = ['default' => 'textfield'];
$options['limit'] = ['default' => TRUE];
$options['vid'] = ['default' => ''];
$options['hierarchy'] = ['default' => FALSE];
$options['error_message'] = ['default' => TRUE];
return $options;
}
public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
$vocabularies = $this->vocabularyStorage->loadMultiple();
$options = array();
$options = [];
foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label();
}
@ -118,56 +118,56 @@ class TaxonomyIndexTid extends ManyToOne {
}
if (empty($this->definition['vocabulary'])) {
$form['vid'] = array(
$form['vid'] = [
'#type' => 'radios',
'#title' => $this->t('Vocabulary'),
'#options' => $options,
'#description' => $this->t('Select which vocabulary to show terms for in the regular options.'),
'#default_value' => $this->options['vid'],
);
];
}
}
$form['type'] = array(
$form['type'] = [
'#type' => 'radios',
'#title' => $this->t('Selection type'),
'#options' => array('select' => $this->t('Dropdown'), 'textfield' => $this->t('Autocomplete')),
'#options' => ['select' => $this->t('Dropdown'), 'textfield' => $this->t('Autocomplete')],
'#default_value' => $this->options['type'],
);
];
$form['hierarchy'] = array(
$form['hierarchy'] = [
'#type' => 'checkbox',
'#title' => $this->t('Show hierarchy in dropdown'),
'#default_value' => !empty($this->options['hierarchy']),
'#states' => array(
'visible' => array(
':input[name="options[type]"]' => array('value' => 'select'),
),
),
);
'#states' => [
'visible' => [
':input[name="options[type]"]' => ['value' => 'select'],
],
],
];
}
protected function valueForm(&$form, FormStateInterface $form_state) {
$vocabulary = $this->vocabularyStorage->load($this->options['vid']);
if (empty($vocabulary) && $this->options['limit']) {
$form['markup'] = array(
$form['markup'] = [
'#markup' => '<div class="js-form-item form-item">' . $this->t('An invalid vocabulary is selected. Please change it in the options.') . '</div>',
);
];
return;
}
if ($this->options['type'] == 'textfield') {
$terms = $this->value ? Term::loadMultiple(($this->value)) : array();
$form['value'] = array(
'#title' => $this->options['limit'] ? $this->t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->label())) : $this->t('Select terms'),
$terms = $this->value ? Term::loadMultiple(($this->value)) : [];
$form['value'] = [
'#title' => $this->options['limit'] ? $this->t('Select terms from vocabulary @voc', ['@voc' => $vocabulary->label()]) : $this->t('Select terms'),
'#type' => 'textfield',
'#default_value' => EntityAutocomplete::getEntityLabels($terms),
);
];
if ($this->options['limit']) {
$form['value']['#type'] = 'entity_autocomplete';
$form['value']['#target_type'] = 'taxonomy_term';
$form['value']['#selection_settings']['target_bundles'] = array($vocabulary->id());
$form['value']['#selection_settings']['target_bundles'] = [$vocabulary->id()];
$form['value']['#tags'] = TRUE;
$form['value']['#process_default_value'] = FALSE;
}
@ -175,18 +175,18 @@ class TaxonomyIndexTid extends ManyToOne {
else {
if (!empty($this->options['hierarchy']) && $this->options['limit']) {
$tree = $this->termStorage->loadTree($vocabulary->id(), 0, NULL, TRUE);
$options = array();
$options = [];
if ($tree) {
foreach ($tree as $term) {
$choice = new \stdClass();
$choice->option = array($term->id() => str_repeat('-', $term->depth) . \Drupal::entityManager()->getTranslationFromContext($term)->label());
$choice->option = [$term->id() => str_repeat('-', $term->depth) . \Drupal::entityManager()->getTranslationFromContext($term)->label()];
$options[] = $choice;
}
}
}
else {
$options = array();
$options = [];
$query = \Drupal::entityQuery('taxonomy_term')
// @todo Sorting on vocabulary properties -
// https://www.drupal.org/node/1821274.
@ -211,7 +211,7 @@ class TaxonomyIndexTid extends ManyToOne {
$options = $this->reduceValueOptions($options);
if (!empty($this->options['expose']['multiple']) && empty($this->options['expose']['required'])) {
$default_value = array();
$default_value = [];
}
}
@ -225,7 +225,7 @@ class TaxonomyIndexTid extends ManyToOne {
}
// Due to #1464174 there is a chance that array('') was saved in the admin ui.
// Let's choose a safe default value.
elseif ($default_value == array('')) {
elseif ($default_value == ['']) {
$default_value = 'All';
}
else {
@ -234,14 +234,14 @@ class TaxonomyIndexTid extends ManyToOne {
}
}
}
$form['value'] = array(
$form['value'] = [
'#type' => 'select',
'#title' => $this->options['limit'] ? $this->t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->label())) : $this->t('Select terms'),
'#title' => $this->options['limit'] ? $this->t('Select terms from vocabulary @voc', ['@voc' => $vocabulary->label()]) : $this->t('Select terms'),
'#multiple' => TRUE,
'#options' => $options,
'#size' => min(9, count($options)),
'#default_value' => $default_value,
);
];
$user_input = $form_state->getUserInput();
if ($exposed && isset($identifier) && !isset($user_input[$identifier])) {
@ -265,13 +265,13 @@ class TaxonomyIndexTid extends ManyToOne {
return;
}
$tids = array();
if ($values = $form_state->getValue(array('options', 'value'))) {
$tids = [];
if ($values = $form_state->getValue(['options', 'value'])) {
foreach ($values as $value) {
$tids[] = $value['target_id'];
}
}
$form_state->setValue(array('options', 'value'), $tids);
$form_state->setValue(['options', 'value'], $tids);
}
public function acceptExposedInput($input) {
@ -348,16 +348,16 @@ class TaxonomyIndexTid extends ManyToOne {
if ($this->options['type'] != 'select') {
unset($form['expose']['reduce']);
}
$form['error_message'] = array(
$form['error_message'] = [
'#type' => 'checkbox',
'#title' => $this->t('Display error message'),
'#default_value' => !empty($this->options['error_message']),
);
];
}
public function adminSummary() {
// set up $this->valueOptions for the parent summary
$this->valueOptions = array();
$this->valueOptions = [];
if ($this->value) {
$this->value = array_filter($this->value);

View file

@ -17,15 +17,15 @@ use Drupal\Core\Form\FormStateInterface;
class TaxonomyIndexTidDepth extends TaxonomyIndexTid {
public function operatorOptions($which = 'title') {
return array(
return [
'or' => $this->t('Is one of'),
);
];
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['depth'] = array('default' => 0);
$options['depth'] = ['default' => 0];
return $options;
}
@ -33,12 +33,12 @@ class TaxonomyIndexTidDepth extends TaxonomyIndexTid {
public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildExtraOptionsForm($form, $form_state);
$form['depth'] = array(
$form['depth'] = [
'#type' => 'weight',
'#title' => $this->t('Depth'),
'#default_value' => $this->options['depth'],
'#description' => $this->t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'),
);
];
}
public function query() {

View file

@ -74,24 +74,24 @@ class NodeTermData extends RelationshipPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['vids'] = array('default' => array());
$options['vids'] = ['default' => []];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$vocabularies = $this->vocabularyStorage->loadMultiple();
$options = array();
$options = [];
foreach ($vocabularies as $voc) {
$options[$voc->id()] = $voc->label();
}
$form['vids'] = array(
$form['vids'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Vocabularies'),
'#options' => $options,
'#default_value' => $this->options['vids'],
'#description' => $this->t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'),
);
];
parent::buildOptionsForm($form, $form_state);
}
@ -134,7 +134,7 @@ class NodeTermData extends RelationshipPluginBase {
$query->condition('td.vid', array_filter($this->options['vids']), 'IN');
$query->addTag('taxonomy_term_access');
$query->fields('td');
$query->fields('tn', array('nid'));
$query->fields('tn', ['nid']);
$def['table formula'] = $query;
}

View file

@ -68,7 +68,7 @@ class TermBreadcrumbBuilder implements BreadcrumbBuilderInterface {
foreach (array_reverse($parents) as $term) {
$term = $this->entityManager->getTranslationFromContext($term);
$breadcrumb->addCacheableDependency($term);
$breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', array('taxonomy_term' => $term->id())));
$breadcrumb->addLink(Link::createFromRoute($term->getName(), 'entity.taxonomy_term.canonical', ['taxonomy_term' => $term->id()]));
}
// This breadcrumb builder is based on a route parameter, and hence it

View file

@ -23,12 +23,12 @@ class TermForm extends ContentEntityForm {
$form_state->set(['taxonomy', 'parent'], $parent);
$form_state->set(['taxonomy', 'vocabulary'], $vocabulary);
$form['relations'] = array(
$form['relations'] = [
'#type' => 'details',
'#title' => $this->t('Relations'),
'#open' => $vocabulary->getHierarchy() == VocabularyInterface::HIERARCHY_MULTIPLE,
'#weight' => 10,
);
];
// \Drupal\taxonomy\TermStorageInterface::loadTree() and
// \Drupal\taxonomy\TermStorageInterface::loadParents() may contain large
@ -46,9 +46,9 @@ class TermForm extends ContentEntityForm {
$exclude[] = $term->id();
$tree = $taxonomy_storage->loadTree($vocabulary->id());
$options = array('<' . $this->t('root') . '>');
$options = ['<' . $this->t('root') . '>'];
if (empty($parent)) {
$parent = array(0);
$parent = [0];
}
foreach ($tree as $item) {
@ -57,33 +57,33 @@ class TermForm extends ContentEntityForm {
}
}
$form['relations']['parent'] = array(
$form['relations']['parent'] = [
'#type' => 'select',
'#title' => $this->t('Parent terms'),
'#options' => $options,
'#default_value' => $parent,
'#multiple' => TRUE,
);
];
}
$form['relations']['weight'] = array(
$form['relations']['weight'] = [
'#type' => 'textfield',
'#title' => $this->t('Weight'),
'#size' => 6,
'#default_value' => $term->getWeight(),
'#description' => $this->t('Terms are displayed in ascending order by weight.'),
'#required' => TRUE,
);
];
$form['vid'] = array(
$form['vid'] = [
'#type' => 'value',
'#value' => $vocabulary->id(),
);
];
$form['tid'] = array(
$form['tid'] = [
'#type' => 'value',
'#value' => $term->id(),
);
];
return parent::form($form, $form_state, $term);
}
@ -127,21 +127,21 @@ class TermForm extends ContentEntityForm {
$view_link = $term->link($term->getName());
switch ($result) {
case SAVED_NEW:
drupal_set_message($this->t('Created new term %term.', array('%term' => $view_link)));
$this->logger('taxonomy')->notice('Created new term %term.', array('%term' => $term->getName(), 'link' => $edit_link));
drupal_set_message($this->t('Created new term %term.', ['%term' => $view_link]));
$this->logger('taxonomy')->notice('Created new term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated term %term.', array('%term' => $view_link)));
$this->logger('taxonomy')->notice('Updated term %term.', array('%term' => $term->getName(), 'link' => $edit_link));
drupal_set_message($this->t('Updated term %term.', ['%term' => $view_link]));
$this->logger('taxonomy')->notice('Updated term %term.', ['%term' => $term->getName(), 'link' => $edit_link]);
break;
}
$current_parent_count = count($form_state->getValue('parent'));
$previous_parent_count = count($form_state->get(['taxonomy', 'parent']));
// Root doesn't count if it's the only parent.
if ($current_parent_count == 1 && $form_state->hasValue(array('parent', 0))) {
if ($current_parent_count == 1 && $form_state->hasValue(['parent', 0])) {
$current_parent_count = 0;
$form_state->setValue('parent', array());
$form_state->setValue('parent', []);
}
// If the number of parents has been reduced to one or none, do a check on the

View file

@ -15,49 +15,49 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*
* @var array
*/
protected $parents = array();
protected $parents = [];
/**
* Array of all loaded term ancestry keyed by ancestor term ID.
*
* @var array
*/
protected $parentsAll = array();
protected $parentsAll = [];
/**
* Array of child terms keyed by parent term ID.
*
* @var array
*/
protected $children = array();
protected $children = [];
/**
* Array of term parents keyed by vocabulary ID and child term ID.
*
* @var array
*/
protected $treeParents = array();
protected $treeParents = [];
/**
* Array of term ancestors keyed by vocabulary ID and parent term ID.
*
* @var array
*/
protected $treeChildren = array();
protected $treeChildren = [];
/**
* Array of terms in a tree keyed by vocabulary ID and term ID.
*
* @var array
*/
protected $treeTerms = array();
protected $treeTerms = [];
/**
* Array of loaded trees keyed by a cache id matching tree arguments.
*
* @var array
*/
protected $trees = array();
protected $trees = [];
/**
* {@inheritdoc}
@ -66,10 +66,10 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
* An array of values to set, keyed by property name. A value for the
* vocabulary ID ('vid') is required.
*/
public function create(array $values = array()) {
public function create(array $values = []) {
// Save new terms with no parents by default.
if (empty($values['parent'])) {
$values['parent'] = array(0);
$values['parent'] = [0];
}
$entity = parent::create($values);
return $entity;
@ -80,13 +80,13 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function resetCache(array $ids = NULL) {
drupal_static_reset('taxonomy_term_count_nodes');
$this->parents = array();
$this->parentsAll = array();
$this->children = array();
$this->treeChildren = array();
$this->treeParents = array();
$this->treeTerms = array();
$this->trees = array();
$this->parents = [];
$this->parentsAll = [];
$this->children = [];
$this->treeChildren = [];
$this->treeParents = [];
$this->treeTerms = [];
$this->trees = [];
parent::resetCache($ids);
}
@ -104,13 +104,13 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function updateTermHierarchy(EntityInterface $term) {
$query = $this->database->insert('taxonomy_term_hierarchy')
->fields(array('tid', 'parent'));
->fields(['tid', 'parent']);
foreach ($term->parent as $parent) {
$query->values(array(
$query->values([
'tid' => $term->id(),
'parent' => (int) $parent->target_id,
));
]);
}
$query->execute();
}
@ -120,7 +120,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function loadParents($tid) {
if (!isset($this->parents[$tid])) {
$parents = array();
$parents = [];
$query = $this->database->select('taxonomy_term_field_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.parent = t.tid');
$query->addField('t', 'tid');
@ -142,7 +142,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function loadAllParents($tid) {
if (!isset($this->parentsAll[$tid])) {
$parents = array();
$parents = [];
if ($term = $this->load($tid)) {
$parents[$term->id()] = $term;
$terms_to_search[] = $term->id();
@ -169,7 +169,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function loadChildren($tid, $vid = NULL) {
if (!isset($this->children[$tid])) {
$children = array();
$children = [];
$query = $this->database->select('taxonomy_term_field_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
$query->addField('t', 'tid');
@ -198,15 +198,15 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
// We cache trees, so it's not CPU-intensive to call on a term and its
// children, too.
if (!isset($this->treeChildren[$vid])) {
$this->treeChildren[$vid] = array();
$this->treeParents[$vid] = array();
$this->treeTerms[$vid] = array();
$this->treeChildren[$vid] = [];
$this->treeParents[$vid] = [];
$this->treeTerms[$vid] = [];
$query = $this->database->select('taxonomy_term_field_data', 't');
$query->join('taxonomy_term_hierarchy', 'h', 'h.tid = t.tid');
$result = $query
->addTag('taxonomy_term_access')
->fields('t')
->fields('h', array('parent'))
->fields('h', ['parent'])
->condition('t.vid', $vid)
->condition('t.default_langcode', 1)
->orderBy('t.weight')
@ -221,17 +221,17 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
// Load full entities, if necessary. The entity controller statically
// caches the results.
$term_entities = array();
$term_entities = [];
if ($load_entities) {
$term_entities = $this->loadMultiple(array_keys($this->treeTerms[$vid]));
}
$max_depth = (!isset($max_depth)) ? count($this->treeChildren[$vid]) : $max_depth;
$tree = array();
$tree = [];
// Keeps track of the parents we have to process, the last entry is used
// for the next processing step.
$process_parents = array();
$process_parents = [];
$process_parents[] = $parent;
// Loops over the parent terms and adds its children to the tree array.
@ -304,7 +304,7 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
*/
public function resetWeights($vid) {
$this->database->update('taxonomy_term_field_data')
->fields(array('weight' => 0))
->fields(['weight' => 0])
->condition('vid', $vid)
->execute();
}
@ -312,10 +312,10 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
/**
* {@inheritdoc}
*/
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL) {
public function getNodeTerms(array $nids, array $vocabs = [], $langcode = NULL) {
$query = db_select('taxonomy_term_field_data', 'td');
$query->innerJoin('taxonomy_index', 'tn', 'td.tid = tn.tid');
$query->fields('td', array('tid'));
$query->fields('td', ['tid']);
$query->addField('tn', 'nid', 'node_nid');
$query->orderby('td.weight');
$query->orderby('td.name');
@ -328,15 +328,15 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
$query->condition('td.langcode', $langcode);
}
$results = array();
$all_tids = array();
$results = [];
$all_tids = [];
foreach ($query->execute() as $term_record) {
$results[$term_record->node_nid][] = $term_record->tid;
$all_tids[] = $term_record->tid;
}
$all_terms = $this->loadMultiple($all_tids);
$terms = array();
$terms = [];
foreach ($results as $nid => $tids) {
foreach ($tids as $tid) {
$terms[$nid][$tid] = $all_terms[$tid];
@ -361,13 +361,13 @@ class TermStorage extends SqlContentEntityStorage implements TermStorageInterfac
public function __wakeup() {
parent::__wakeup();
// Initialize static caches.
$this->parents = array();
$this->parentsAll = array();
$this->children = array();
$this->treeChildren = array();
$this->treeParents = array();
$this->treeTerms = array();
$this->trees = array();
$this->parents = [];
$this->parentsAll = [];
$this->children = [];
$this->treeChildren = [];
$this->treeParents = [];
$this->treeTerms = [];
$this->trees = [];
}
}

View file

@ -116,6 +116,6 @@ interface TermStorageInterface extends ContentEntityStorageInterface {
* @return array
* An array of nids and the term entities they were tagged with.
*/
public function getNodeTerms(array $nids, array $vocabs = array(), $langcode = NULL);
public function getNodeTerms(array $nids, array $vocabs = [], $langcode = NULL);
}

View file

@ -17,93 +17,93 @@ class TermStorageSchema extends SqlContentEntityStorageSchema {
protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
$schema = parent::getEntitySchema($entity_type, $reset = FALSE);
$schema['taxonomy_term_field_data']['indexes'] += array(
'taxonomy_term__tree' => array('vid', 'weight', 'name'),
'taxonomy_term__vid_name' => array('vid', 'name'),
);
$schema['taxonomy_term_field_data']['indexes'] += [
'taxonomy_term__tree' => ['vid', 'weight', 'name'],
'taxonomy_term__vid_name' => ['vid', 'name'],
];
$schema['taxonomy_term_hierarchy'] = array(
$schema['taxonomy_term_hierarchy'] = [
'description' => 'Stores the hierarchical relationship between terms.',
'fields' => array(
'tid' => array(
'fields' => [
'tid' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Primary Key: The {taxonomy_term_data}.tid of the term.',
),
'parent' => array(
],
'parent' => [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => "Primary Key: The {taxonomy_term_data}.tid of the term's parent. 0 indicates no parent.",
),
),
'indexes' => array(
'parent' => array('parent'),
),
'foreign keys' => array(
'taxonomy_term_data' => array(
],
],
'indexes' => [
'parent' => ['parent'],
],
'foreign keys' => [
'taxonomy_term_data' => [
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
),
'primary key' => array('tid', 'parent'),
);
'columns' => ['tid' => 'tid'],
],
],
'primary key' => ['tid', 'parent'],
];
$schema['taxonomy_index'] = array(
$schema['taxonomy_index'] = [
'description' => 'Maintains denormalized information about node/term relationships.',
'fields' => array(
'nid' => array(
'fields' => [
'nid' => [
'description' => 'The {node}.nid this record tracks.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'tid' => array(
],
'tid' => [
'description' => 'The term ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'status' => array(
],
'status' => [
'description' => 'Boolean indicating whether the node is published (visible to non-administrators).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'sticky' => array(
],
'sticky' => [
'description' => 'Boolean indicating whether the node is sticky.',
'type' => 'int',
'not null' => FALSE,
'default' => 0,
'size' => 'tiny',
),
'created' => array(
],
'created' => [
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('nid', 'tid'),
'indexes' => array(
'term_node' => array('tid', 'status', 'sticky', 'created'),
),
'foreign keys' => array(
'tracked_node' => array(
],
],
'primary key' => ['nid', 'tid'],
'indexes' => [
'term_node' => ['tid', 'status', 'sticky', 'created'],
],
'foreign keys' => [
'tracked_node' => [
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'term' => array(
'columns' => ['nid' => 'nid'],
],
'term' => [
'table' => 'taxonomy_term_data',
'columns' => array('tid' => 'tid'),
),
),
);
'columns' => ['tid' => 'tid'],
],
],
];
return $schema;
}

View file

@ -16,7 +16,7 @@ class TermTranslationHandler extends ContentTranslationHandler {
*/
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
$form['actions']['submit']['#submit'][] = array($this, 'entityFormSave');
$form['actions']['submit']['#submit'][] = [$this, 'entityFormSave'];
}
/**
@ -26,7 +26,7 @@ class TermTranslationHandler extends ContentTranslationHandler {
*
* @see \Drupal\Core\Entity\EntityForm::build()
*/
function entityFormSave(array $form, FormStateInterface $form_state) {
public function entityFormSave(array $form, FormStateInterface $form_state) {
if ($this->getSourceLangcode($form_state)) {
$entity = $form_state->getFormObject()->getEntity();
// We need a redirect here, otherwise we would get an access denied page,

View file

@ -16,10 +16,10 @@ class TermViewBuilder extends EntityViewBuilder {
*/
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()),
);
$build['#contextual_links']['taxonomy_term'] = [
'route_parameters' => ['taxonomy_term' => $entity->id()],
'metadata' => ['changed' => $entity->getChangedTime()],
];
}
}

View file

@ -19,13 +19,13 @@ class TermViewsData extends EntityViewsData {
$data['taxonomy_term_field_data']['table']['base']['access query tag'] = 'taxonomy_term_access';
$data['taxonomy_term_field_data']['table']['wizard_id'] = 'taxonomy_term';
$data['taxonomy_term_field_data']['table']['join'] = array(
$data['taxonomy_term_field_data']['table']['join'] = [
// This is provided for the many_to_one argument.
'taxonomy_index' => array(
'taxonomy_index' => [
'field' => 'tid',
'left_field' => 'tid',
),
);
],
];
$data['taxonomy_term_field_data']['tid']['help'] = $this->t('The tid of a taxonomy term.');
@ -39,18 +39,18 @@ class TermViewsData extends EntityViewsData {
$data['taxonomy_term_field_data']['tid']['filter']['hierarchy table'] = 'taxonomy_term_hierarchy';
$data['taxonomy_term_field_data']['tid']['filter']['numeric'] = TRUE;
$data['taxonomy_term_field_data']['tid_raw'] = array(
$data['taxonomy_term_field_data']['tid_raw'] = [
'title' => $this->t('Term ID'),
'help' => $this->t('The tid of a taxonomy term.'),
'real field' => 'tid',
'filter' => array(
'filter' => [
'id' => 'numeric',
'allow empty' => TRUE,
),
);
],
];
$data['taxonomy_term_field_data']['tid_representative'] = array(
'relationship' => array(
$data['taxonomy_term_field_data']['tid_representative'] = [
'relationship' => [
'title' => $this->t('Representative node'),
'label' => $this->t('Representative node'),
'help' => $this->t('Obtains a single representative node for each term, according to a chosen sort criterion.'),
@ -62,12 +62,12 @@ class TermViewsData extends EntityViewsData {
'base' => 'node_field_data',
'field' => 'nid',
'relationship' => 'node_field_data:term_node_tid'
),
);
],
];
$data['taxonomy_term_field_data']['vid']['help'] = $this->t('Filter the results of "Taxonomy: Term" to a particular vocabulary.');
unset($data['taxonomy_term_field_data']['vid']['field']);
unset($data['taxonomy_term_field_data']['vid']['argument']);
$data['taxonomy_term_field_data']['vid']['argument']['id'] = 'vocabulary_vid';
unset($data['taxonomy_term_field_data']['vid']['sort']);
$data['taxonomy_term_field_data']['name']['field']['id'] = 'term_name';
@ -79,114 +79,114 @@ class TermViewsData extends EntityViewsData {
$data['taxonomy_term_field_data']['changed']['title'] = $this->t('Updated date');
$data['taxonomy_term_field_data']['changed']['help'] = $this->t('The date the term was last updated.');
$data['taxonomy_term_field_data']['changed_fulldate'] = array(
$data['taxonomy_term_field_data']['changed_fulldate'] = [
'title' => $this->t('Updated date'),
'help' => $this->t('Date in the form of CCYYMMDD.'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_fulldate',
),
);
],
];
$data['taxonomy_term_field_data']['changed_year_month'] = array(
$data['taxonomy_term_field_data']['changed_year_month'] = [
'title' => $this->t('Updated year + month'),
'help' => $this->t('Date in the form of YYYYMM.'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_year_month',
),
);
],
];
$data['taxonomy_term_field_data']['changed_year'] = array(
$data['taxonomy_term_field_data']['changed_year'] = [
'title' => $this->t('Updated year'),
'help' => $this->t('Date in the form of YYYY.'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_year',
),
);
],
];
$data['taxonomy_term_field_data']['changed_month'] = array(
$data['taxonomy_term_field_data']['changed_month'] = [
'title' => $this->t('Updated month'),
'help' => $this->t('Date in the form of MM (01 - 12).'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_month',
),
);
],
];
$data['taxonomy_term_field_data']['changed_day'] = array(
$data['taxonomy_term_field_data']['changed_day'] = [
'title' => $this->t('Updated day'),
'help' => $this->t('Date in the form of DD (01 - 31).'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_day',
),
);
],
];
$data['taxonomy_term_field_data']['changed_week'] = array(
$data['taxonomy_term_field_data']['changed_week'] = [
'title' => $this->t('Updated week'),
'help' => $this->t('Date in the form of WW (01 - 53).'),
'argument' => array(
'argument' => [
'field' => 'changed',
'id' => 'date_week',
),
);
],
];
$data['taxonomy_index']['table']['group'] = $this->t('Taxonomy term');
$data['taxonomy_index']['table']['join'] = array(
'taxonomy_term_field_data' => array(
$data['taxonomy_index']['table']['join'] = [
'taxonomy_term_field_data' => [
// links directly to taxonomy_term_field_data via tid
'left_field' => 'tid',
'field' => 'tid',
),
'node_field_data' => array(
],
'node_field_data' => [
// links directly to node via nid
'left_field' => 'nid',
'field' => 'nid',
),
'taxonomy_term_hierarchy' => array(
],
'taxonomy_term_hierarchy' => [
'left_field' => 'tid',
'field' => 'tid',
),
);
],
];
$data['taxonomy_index']['nid'] = array(
$data['taxonomy_index']['nid'] = [
'title' => $this->t('Content with term'),
'help' => $this->t('Relate all content tagged with a term.'),
'relationship' => array(
'relationship' => [
'id' => 'standard',
'base' => 'node',
'base field' => 'nid',
'label' => $this->t('node'),
'skip base' => 'node',
),
);
],
];
// @todo This stuff needs to move to a node field since really it's all
// about nodes.
$data['taxonomy_index']['tid'] = array(
$data['taxonomy_index']['tid'] = [
'group' => $this->t('Content'),
'title' => $this->t('Has taxonomy term ID'),
'help' => $this->t('Display content if it has the selected taxonomy terms.'),
'argument' => array(
'argument' => [
'id' => 'taxonomy_index_tid',
'name table' => 'taxonomy_term_field_data',
'name field' => 'name',
'empty field name' => $this->t('Uncategorized'),
'numeric' => TRUE,
'skip base' => 'taxonomy_term_field_data',
),
'filter' => array(
],
'filter' => [
'title' => $this->t('Has taxonomy term'),
'id' => 'taxonomy_index_tid',
'hierarchy table' => 'taxonomy_term_hierarchy',
'numeric' => TRUE,
'skip base' => 'taxonomy_term_field_data',
'allow empty' => TRUE,
),
);
],
];
$data['taxonomy_index']['status'] = [
'title' => $this->t('Publish status'),
@ -226,37 +226,37 @@ class TermViewsData extends EntityViewsData {
$data['taxonomy_term_hierarchy']['table']['group'] = $this->t('Taxonomy term');
$data['taxonomy_term_hierarchy']['table']['provider'] = 'taxonomy';
$data['taxonomy_term_hierarchy']['table']['join'] = array(
'taxonomy_term_hierarchy' => array(
$data['taxonomy_term_hierarchy']['table']['join'] = [
'taxonomy_term_hierarchy' => [
// Link to self through left.parent = right.tid (going down in depth).
'left_field' => 'tid',
'field' => 'parent',
),
'taxonomy_term_field_data' => array(
],
'taxonomy_term_field_data' => [
// Link directly to taxonomy_term_field_data via tid.
'left_field' => 'tid',
'field' => 'tid',
),
);
],
];
$data['taxonomy_term_hierarchy']['parent'] = array(
$data['taxonomy_term_hierarchy']['parent'] = [
'title' => $this->t('Parent term'),
'help' => $this->t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
'relationship' => array(
'relationship' => [
'base' => 'taxonomy_term_field_data',
'field' => 'parent',
'label' => $this->t('Parent'),
'id' => 'standard',
),
'filter' => array(
],
'filter' => [
'help' => $this->t('Filter the results of "Taxonomy: Term" by the parent pid.'),
'id' => 'numeric',
),
'argument' => array(
],
'argument' => [
'help' => $this->t('The parent term of the term.'),
'id' => 'taxonomy',
),
);
],
];
return $data;
}

View file

@ -18,7 +18,7 @@ class RssTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('node', 'field_ui', 'views');
public static $modules = ['node', 'field_ui', 'views'];
/**
* Vocabulary for testing.
@ -41,23 +41,23 @@ class RssTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->fieldName = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName, array(
->setComponent($this->fieldName, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName, array(
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
))
])
->save();
}
@ -66,26 +66,27 @@ class RssTest extends TaxonomyTestBase {
*
* Create a node and assert that taxonomy terms appear in rss.xml.
*/
function testTaxonomyRss() {
public function testTaxonomyRss() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
// RSS display must be added manually.
$this->drupalGet("admin/structure/types/manage/article/display");
$edit = array(
$edit = [
"display_modes_custom[rss]" => '1',
);
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// Change the format to 'RSS category'.
$this->drupalGet("admin/structure/types/manage/article/display/rss");
$edit = array(
$edit = [
"fields[taxonomy_" . $this->vocabulary->id() . "][type]" => 'entity_reference_rss_category',
);
"fields[taxonomy_" . $this->vocabulary->id() . "][region]" => 'content',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
// Post an article.
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit[$this->fieldName . '[]'] = $term1->id();
$this->drupalPostForm('node/add/article', $edit, t('Save'));
@ -94,7 +95,7 @@ class RssTest extends TaxonomyTestBase {
$this->drupalGet('rss.xml');
$test_element = sprintf(
'<category %s>%s</category>',
'domain="' . $term1->url('canonical', array('absolute' => TRUE)) . '"',
'domain="' . $term1->url('canonical', ['absolute' => TRUE]) . '"',
$term1->getName()
);
$this->assertRaw($test_element, 'Term is displayed when viewing the rss feed.');

View file

@ -26,48 +26,48 @@ class TaxonomyImageTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('image');
public static $modules = ['image'];
protected function setUp() {
parent::setUp();
// Remove access content permission from registered users.
user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, array('access content'));
user_role_revoke_permissions(RoleInterface::AUTHENTICATED_ID, ['access content']);
$this->vocabulary = $this->createVocabulary();
// Add a field to the vocabulary.
$entity_type = 'taxonomy_term';
$name = 'field_test';
FieldStorageConfig::create(array(
FieldStorageConfig::create([
'field_name' => $name,
'entity_type' => $entity_type,
'type' => 'image',
'settings' => array(
'settings' => [
'uri_scheme' => 'private',
),
))->save();
],
])->save();
FieldConfig::create([
'field_name' => $name,
'entity_type' => $entity_type,
'bundle' => $this->vocabulary->id(),
'settings' => array(),
'settings' => [],
])->save();
entity_get_display($entity_type, $this->vocabulary->id(), 'default')
->setComponent($name, array(
->setComponent($name, [
'type' => 'image',
'settings' => array(),
))
'settings' => [],
])
->save();
entity_get_form_display($entity_type, $this->vocabulary->id(), 'default')
->setComponent($name, array(
->setComponent($name, [
'type' => 'image_image',
'settings' => array(),
))
'settings' => [],
])
->save();
}
public function testTaxonomyImageAccess() {
$user = $this->drupalCreateUser(array('administer site configuration', 'administer taxonomy', 'access user profiles'));
$user = $this->drupalCreateUser(['administer site configuration', 'administer taxonomy', 'access user profiles']);
$this->drupalLogin($user);
// Create a term and upload the image.
@ -77,12 +77,12 @@ class TaxonomyImageTest extends TaxonomyTestBase {
$edit['files[field_test_0]'] = drupal_realpath($image->uri);
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
$this->drupalPostForm(NULL, ['field_test[0][alt]' => $this->randomMachineName()], t('Save'));
$terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $edit['name[0][value]']));
$terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $edit['name[0][value]']]);
$term = reset($terms);
$this->assertText(t('Created new term @name.', array('@name' => $term->getName())));
$this->assertText(t('Created new term @name.', ['@name' => $term->getName()]));
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(array('access content'));
$access_user = $this->drupalCreateUser(['access content']);
$no_access_user = $this->drupalCreateUser();
$image = File::load($term->field_test->target_id);
$this->drupalLogin($access_user);

View file

@ -26,7 +26,7 @@ class TaxonomyQueryAlterTest extends WebTestBase {
public function testTaxonomyQueryAlter() {
// Create a new vocabulary and add a few terms to it.
$vocabulary = $this->createVocabulary();
$terms = array();
$terms = [];
for ($i = 0; $i < 5; $i++) {
$terms[$i] = $this->createTerm($vocabulary);
}

View file

@ -14,7 +14,7 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* Vocabulary for testing.
@ -32,7 +32,7 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
/**
* Tests term indentation.
*/
function testTermIndentation() {
public function testTermIndentation() {
// Create three taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
@ -42,12 +42,12 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Indent the second term under the first one.
$edit = array(
$edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 1,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 1,
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
);
];
// Submit the edited form and check for HTML indentation element presence.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview', $edit, t('Save'));
@ -58,12 +58,12 @@ class TaxonomyTermIndentationTest extends TaxonomyTestBase {
$this->assertEqual(key($parents), 1, 'Term 1 is the term 2\'s parent');
// Move the second term back out to the root level.
$edit = array(
$edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term2->id() . ':0][weight]' => 1,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid' ) . '/overview', $edit, t('Save'));
// All terms back at the root level, no indentation should be present.

View file

@ -7,6 +7,9 @@ use Drupal\simpletest\WebTestBase;
/**
* Provides common helper methods for Taxonomy module tests.
*
* @deprecated Scheduled for removal in Drupal 9.0.0.
* Use \Drupal\Tests\taxonomy\Functional\TaxonomyTestBase instead.
*/
abstract class TaxonomyTestBase extends WebTestBase {
@ -18,7 +21,7 @@ abstract class TaxonomyTestBase extends WebTestBase {
*
* @var array
*/
public static $modules = array('taxonomy', 'block');
public static $modules = ['taxonomy', 'block'];
/**
* {@inheritdoc}
@ -29,7 +32,7 @@ abstract class TaxonomyTestBase extends WebTestBase {
// Create Basic page and Article node types.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}
}

View file

@ -15,7 +15,7 @@ trait TaxonomyTestTrait {
/**
* Returns a new vocabulary with random properties.
*/
function createVocabulary() {
public function createVocabulary() {
// Create a vocabulary.
$vocabulary = Vocabulary::create([
'name' => $this->randomMachineName(),
@ -40,7 +40,7 @@ trait TaxonomyTestTrait {
* @return \Drupal\taxonomy\Entity\Term
* The new taxonomy term object.
*/
function createTerm(Vocabulary $vocabulary, $values = array()) {
public function createTerm(Vocabulary $vocabulary, $values = []) {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$term = Term::create($values + [

View file

@ -79,26 +79,26 @@ trait TaxonomyTranslationTestTrait {
* to FALSE.
*/
protected function setUpTermReferenceField() {
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$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(FALSE);
$field_storage->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, array(
->setComponent($this->termFieldName, [
'type' => 'entity_reference_autocomplete_tags',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->termFieldName, array(
->setComponent($this->termFieldName, [
'type' => 'entity_reference_label',
))
])
->save();
}

View file

@ -52,31 +52,31 @@ class TermTest extends TaxonomyTestBase {
$field_name = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$this->field = FieldConfig::loadByName('node', 'article', $field_name);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'entity_reference_label',
))
])
->save();
}
/**
* Test terms in a single and multiple hierarchy.
*/
function testTaxonomyTermHierarchy() {
public function testTaxonomyTermHierarchy() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
@ -89,8 +89,8 @@ class TermTest extends TaxonomyTestBase {
$this->assertEqual(0, $vocabulary->getHierarchy(), 'Vocabulary is flat.');
// Edit $term2, setting $term1 as parent.
$edit = array();
$edit['parent[]'] = array($term1->id());
$edit = [];
$edit['parent[]'] = [$term1->id()];
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
// Check the hierarchy.
@ -107,7 +107,7 @@ class TermTest extends TaxonomyTestBase {
// Create a third term and save this as a parent of term2.
$term3 = $this->createTerm($this->vocabulary);
$term2->parent = array($term1->id(), $term3->id());
$term2->parent = [$term1->id(), $term3->id()];
$term2->save();
$parents = $taxonomy_storage->loadParents($term2->id());
$this->assertTrue(isset($parents[$term1->id()]) && isset($parents[$term3->id()]), 'Both parents found successfully.');
@ -116,7 +116,7 @@ class TermTest extends TaxonomyTestBase {
/**
* Tests that many terms with parents show on each page
*/
function testTaxonomyTermChildTerms() {
public function testTaxonomyTermChildTerms() {
// Set limit to 10 terms per page. Set variable to 9 so 10 terms appear.
$this->config('taxonomy.settings')->set('terms_per_page_admin', '9')->save();
$term1 = $this->createTerm($this->vocabulary);
@ -127,7 +127,7 @@ class TermTest extends TaxonomyTestBase {
// Create 40 terms. Terms 1-12 get parent of $term1. All others are
// individual terms.
for ($x = 1; $x <= 40; $x++) {
$edit = array();
$edit = [];
// Set terms in order so we know which terms will be on which pages.
$edit['weight'] = $x;
@ -149,14 +149,14 @@ class TermTest extends TaxonomyTestBase {
}
// Get Page 2.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array('query' => array('page' => 1)));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
$this->assertText($term1->getName(), 'Parent Term is displayed on Page 2');
for ($x = 1; $x <= 18; $x++) {
$this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 2');
}
// Get Page 3.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array('query' => array('page' => 2)));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 2]]);
$this->assertNoText($term1->getName(), 'Parent Term is not displayed on Page 3');
for ($x = 1; $x <= 17; $x++) {
$this->assertNoText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' not found on Page 3');
@ -171,13 +171,13 @@ class TermTest extends TaxonomyTestBase {
*
* Save & edit a node and assert that taxonomy terms are saved/loaded properly.
*/
function testTaxonomyNode() {
public function testTaxonomyNode() {
// Create two taxonomy terms.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
// Post an article.
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit[$this->field->getName() . '[]'] = $term1->id();
@ -190,7 +190,7 @@ class TermTest extends TaxonomyTestBase {
$this->clickLink(t('Edit'));
$this->assertText($term1->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertText($term1->getName(), 'Term is displayed after saving the node with no changes.');
// Edit the node with a different term.
@ -210,28 +210,28 @@ class TermTest extends TaxonomyTestBase {
/**
* Test term creation with a free-tagging vocabulary from the node form.
*/
function testNodeTermCreationAndDeletion() {
public function testNodeTermCreationAndDeletion() {
// Enable tags in the vocabulary.
$field = $this->field;
entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
->setComponent($field->getName(), array(
->setComponent($field->getName(), [
'type' => 'entity_reference_autocomplete_tags',
'settings' => array(
'settings' => [
'placeholder' => 'Start typing here.',
),
))
],
])
->save();
// Prefix the terms with a letter to ensure there is no clash in the first
// three letters.
// @see https://www.drupal.org/node/2397691
$terms = array(
$terms = [
'term1' => 'a' . $this->randomMachineName(),
'term2' => 'b' . $this->randomMachineName(),
'term3' => 'c' . $this->randomMachineName() . ', ' . $this->randomMachineName(),
'term4' => 'd' . $this->randomMachineName(),
);
];
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
// Insert the terms in a comma separated list. Vocabulary 1 is a
@ -255,10 +255,10 @@ class TermTest extends TaxonomyTestBase {
// Save, creating the terms.
$this->drupalPostForm('node/add/article', $edit, t('Save'));
$this->assertText(t('@type @title has been created.', array('@type' => t('Article'), '@title' => $edit['title[0][value]'])), 'The node was created successfully.');
$this->assertText(t('@type @title has been created.', ['@type' => t('Article'), '@title' => $edit['title[0][value]']]), 'The node was created successfully.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'node/'));
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
foreach ($terms as $term) {
@ -266,7 +266,7 @@ class TermTest extends TaxonomyTestBase {
}
// Get the created terms.
$term_objects = array();
$term_objects = [];
foreach ($terms as $key => $term) {
$term_objects[$key] = taxonomy_term_load_multiple_by_name($term);
$term_objects[$key] = reset($term_objects[$key]);
@ -288,30 +288,30 @@ class TermTest extends TaxonomyTestBase {
// Delete term 2 from the term delete page.
$this->drupalGet('taxonomy/term/' . $term_objects['term2']->id() . '/delete');
$this->drupalPostForm(NULL, array(), t('Delete'));
$term_names = array($term_objects['term3']->getName(), $term_objects['term4']->getName());
$this->drupalPostForm(NULL, [], t('Delete'));
$term_names = [$term_objects['term3']->getName(), $term_objects['term4']->getName()];
$this->drupalGet('node/' . $node->id());
foreach ($term_names as $term_name) {
$this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', array('%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName())));
$this->assertText($term_name, format_string('The term %name appears on the node page after two terms, %deleted1 and %deleted2, were deleted.', ['%name' => $term_name, '%deleted1' => $term_objects['term1']->getName(), '%deleted2' => $term_objects['term2']->getName()]));
}
$this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term1']->getName())));
$this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', array('%name' => $term_objects['term2']->getName())));
$this->assertNoText($term_objects['term1']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term1']->getName()]));
$this->assertNoText($term_objects['term2']->getName(), format_string('The deleted term %name does not appear on the node page.', ['%name' => $term_objects['term2']->getName()]));
}
/**
* Save, edit and delete a term using the user interface.
*/
function testTermInterface() {
\Drupal::service('module_installer')->install(array('views'));
$edit = array(
public function testTermInterface() {
\Drupal::service('module_installer')->install(['views']);
$edit = [
'name[0][value]' => $this->randomMachineName(12),
'description[0][value]' => $this->randomMachineName(100),
);
];
// Explicitly set the parents field to 'root', to ensure that
// TermForm::save() handles the invalid term ID correctly.
$edit['parent[]'] = array(0);
$edit['parent[]'] = [0];
// Create the term to edit.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
@ -328,10 +328,10 @@ class TermTest extends TaxonomyTestBase {
$this->assertRaw($edit['name[0][value]'], 'The randomly generated term name is present.');
$this->assertText($edit['description[0][value]'], 'The randomly generated term description is present.');
$edit = array(
$edit = [
'name[0][value]' => $this->randomMachineName(14),
'description[0][value]' => $this->randomMachineName(102),
);
];
// Edit the term.
$this->drupalPostForm('taxonomy/term/' . $term->id() . '/edit', $edit, t('Save'));
@ -380,7 +380,7 @@ class TermTest extends TaxonomyTestBase {
/**
* Save, edit and delete a term using the user interface.
*/
function testTermReorder() {
public function testTermReorder() {
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
$this->createTerm($this->vocabulary);
@ -398,7 +398,7 @@ class TermTest extends TaxonomyTestBase {
// "tid:1:0[depth]", and "tid:1:0[weight]". Change the order to term2,
// term3, term1 by setting weight property, make term3 a child of term2 by
// setting the parent and depth properties, and update all hidden fields.
$edit = array(
$edit = [
'terms[tid:' . $term2->id() . ':0][term][tid]' => $term2->id(),
'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
@ -411,18 +411,18 @@ class TermTest extends TaxonomyTestBase {
'terms[tid:' . $term1->id() . ':0][term][parent]' => 0,
'terms[tid:' . $term1->id() . ':0][term][depth]' => 0,
'terms[tid:' . $term1->id() . ':0][weight]' => 2,
);
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$taxonomy_storage->resetCache();
$terms = $taxonomy_storage->loadTree($this->vocabulary->id());
$this->assertEqual($terms[0]->tid, $term2->id(), 'Term 2 was moved above term 1.');
$this->assertEqual($terms[1]->parents, array($term2->id()), 'Term 3 was made a child of term 2.');
$this->assertEqual($terms[1]->parents, [$term2->id()], 'Term 3 was made a child of term 2.');
$this->assertEqual($terms[2]->tid, $term1->id(), 'Term 1 was moved below term 2.');
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', array(), t('Reset to alphabetical'));
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', [], t('Reset to alphabetical'));
// Submit confirmation form.
$this->drupalPostForm(NULL, array(), t('Reset to alphabetical'));
$this->drupalPostForm(NULL, [], t('Reset to alphabetical'));
// Ensure form redirected back to overview.
$this->assertUrl('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
@ -431,22 +431,22 @@ class TermTest extends TaxonomyTestBase {
$this->assertEqual($terms[0]->id(), $term1->id(), 'Term 1 was moved to back above term 2.');
$this->assertEqual($terms[1]->id(), $term2->id(), 'Term 2 was moved to back below term 1.');
$this->assertEqual($terms[2]->id(), $term3->id(), 'Term 3 is still below term 2.');
$this->assertEqual($terms[2]->parents, array($term2->id()), 'Term 3 is still a child of term 2.');
$this->assertEqual($terms[2]->parents, [$term2->id()], 'Term 3 is still a child of term 2.');
}
/**
* Test saving a term with multiple parents through the UI.
*/
function testTermMultipleParentsInterface() {
public function testTermMultipleParentsInterface() {
// Add a new term to the vocabulary so that we can have multiple parents.
$parent = $this->createTerm($this->vocabulary);
// Add a new term with multiple parents.
$edit = array(
$edit = [
'name[0][value]' => $this->randomMachineName(12),
'description[0][value]' => $this->randomMachineName(100),
'parent[]' => array(0, $parent->id()),
);
'parent[]' => [0, $parent->id()],
];
// Save the new term.
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add', $edit, t('Save'));
@ -466,7 +466,7 @@ class TermTest extends TaxonomyTestBase {
/**
* Test taxonomy_term_load_multiple_by_name().
*/
function testTaxonomyGetTermByName() {
public function testTaxonomyGetTermByName() {
$term = $this->createTerm($this->vocabulary);
// Load the term with the exact name.
@ -526,18 +526,18 @@ class TermTest extends TaxonomyTestBase {
/**
* Tests that editing and saving a node with no changes works correctly.
*/
function testReSavingTags() {
public function testReSavingTags() {
// Enable tags in the vocabulary.
$field = $this->field;
entity_get_form_display($field->getTargetEntityTypeId(), $field->getTargetBundle(), 'default')
->setComponent($field->getName(), array(
->setComponent($field->getName(), [
'type' => 'entity_reference_autocomplete_tags',
))
])
->save();
// Create a term and a node using it.
$term = $this->createTerm($this->vocabulary);
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit['body[0][value]'] = $this->randomMachineName(16);
$edit[$this->field->getName() . '[target_id]'] = $term->getName();
@ -547,7 +547,7 @@ class TermTest extends TaxonomyTestBase {
// changes.
$this->clickLink(t('Edit'));
$this->assertRaw($term->getName(), 'Term is displayed when editing the node.');
$this->drupalPostForm(NULL, array(), t('Save'));
$this->drupalPostForm(NULL, [], t('Save'));
$this->assertRaw($term->getName(), 'Term is displayed after saving the node with no changes.');
}

View file

@ -20,23 +20,23 @@ class TermTranslationTest extends TaxonomyTestBase {
*
* @var array
*/
protected $termTranslationMap = array(
protected $termTranslationMap = [
'one' => 'translatedOne',
'two' => 'translatedTwo',
'three' => 'translatedThree',
);
];
/**
* Created terms.
*
* @var \Drupal\taxonomy\Entity\Term[]
*/
protected $terms = array();
protected $terms = [];
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy', 'language', 'content_translation');
public static $modules = ['taxonomy', 'language', 'content_translation'];
/**
* {@inheritdoc}
@ -55,7 +55,7 @@ class TermTranslationTest extends TaxonomyTestBase {
*/
public function testTranslatedBreadcrumbs() {
// Ensure non-translated breadcrumb is correct.
$breadcrumb = array(Url::fromRoute('<front>')->toString() => 'Home');
$breadcrumb = [Url::fromRoute('<front>')->toString() => 'Home'];
foreach ($this->terms as $term) {
$breadcrumb[$term->url()] = $term->label();
}
@ -69,7 +69,7 @@ class TermTranslationTest extends TaxonomyTestBase {
$languages = \Drupal::languageManager()->getLanguages();
// Construct the expected translated breadcrumb.
$breadcrumb = array(Url::fromRoute('<front>', [], ['language' => $languages[$this->translateToLangcode]])->toString() => 'Home');
$breadcrumb = [Url::fromRoute('<front>', [], ['language' => $languages[$this->translateToLangcode]])->toString() => 'Home'];
foreach ($this->terms as $term) {
$translated = $term->getTranslation($this->translateToLangcode);
$url = $translated->url('canonical', ['language' => $languages[$this->translateToLangcode]]);
@ -87,14 +87,14 @@ class TermTranslationTest extends TaxonomyTestBase {
/**
* Test translation of terms are showed in the node.
*/
protected function testTermsTranslation() {
public function testTermsTranslation() {
// Set the display of the term reference field on the article content type
// to "Check boxes/radio buttons".
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, array(
->setComponent($this->termFieldName, [
'type' => 'options_buttons',
))
])
->save();
$this->drupalLogin($this->drupalCreateUser(['create article content']));
@ -118,15 +118,15 @@ class TermTranslationTest extends TaxonomyTestBase {
$parent_vid = 0;
foreach ($this->termTranslationMap as $name => $translation) {
$term = $this->createTerm($this->vocabulary, array(
$term = $this->createTerm($this->vocabulary, [
'name' => $name,
'langcode' => $this->baseLangcode,
'parent' => $parent_vid,
));
]);
$term->addTranslation($this->translateToLangcode, array(
$term->addTranslation($this->translateToLangcode, [
'name' => $translation,
));
]);
$term->save();
// Each term is nested under the last.

View file

@ -25,7 +25,7 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
*
* @var array
*/
public static $modules = array('language', 'content_translation', 'taxonomy');
public static $modules = ['language', 'content_translation', 'taxonomy'];
protected function setUp() {
$this->entityTypeId = 'taxonomy_term';
@ -54,14 +54,14 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('administer taxonomy'));
return array_merge(parent::getTranslatorPermissions(), ['administer taxonomy']);
}
/**
* {@inheritdoc}
*/
protected function getNewEntityValues($langcode) {
return array('name' => $this->randomMachineName()) + parent::getNewEntityValues($langcode);
return ['name' => $this->randomMachineName()] + parent::getNewEntityValues($langcode);
}
/**
@ -73,7 +73,7 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
// To be able to post values for the configurable base fields (name,
// description) have to be suffixed with [0][value].
foreach ($edit as $property => $value) {
foreach (array('name', 'description') as $key) {
foreach (['name', 'description'] as $key) {
if ($property == $key) {
$edit[$key . '[0][value]'] = $value;
unset($edit[$property]);
@ -91,7 +91,7 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
// Make sure that no row was inserted for taxonomy vocabularies which do
// not have translations enabled.
$rows = db_query('SELECT tid, count(tid) AS count FROM {taxonomy_term_field_data} WHERE vid <> :vid GROUP BY tid', array(':vid' => $this->bundle))->fetchAll();
$rows = db_query('SELECT tid, count(tid) AS count FROM {taxonomy_term_field_data} WHERE vid <> :vid GROUP BY tid', [':vid' => $this->bundle])->fetchAll();
foreach ($rows as $row) {
$this->assertTrue($row->count < 2, 'Term does not have translations.');
}
@ -100,12 +100,12 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
/**
* Tests translate link on vocabulary term list.
*/
function testTranslateLinkVocabularyAdminPage() {
public function testTranslateLinkVocabularyAdminPage() {
$this->drupalLogin($this->drupalCreateUser(array_merge(parent::getTranslatorPermissions(), ['access administration pages', 'administer taxonomy'])));
$values = array(
$values = [
'name' => $this->randomMachineName(),
);
];
$translatable_tid = $this->createEntity($values, $this->langcodes[0], $this->vocabulary->id());
// Create an untranslatable vocabulary.
@ -118,9 +118,9 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
]);
$untranslatable_vocabulary->save();
$values = array(
$values = [
'name' => $this->randomMachineName(),
);
];
$untranslatable_tid = $this->createEntity($values, $this->langcodes[0], $untranslatable_vocabulary->id());
// Verify translation links.
@ -148,14 +148,14 @@ class TermTranslationUITest extends ContentTranslationUITestBase {
foreach ($this->langcodes as $langcode) {
// We only want to test the title for non-english translations.
if ($langcode != 'en') {
$options = array('language' => $languages[$langcode]);
$options = ['language' => $languages[$langcode]];
$url = $entity->urlInfo('edit-form', $options);
$this->drupalGet($url);
$title = t('@title [%language translation]', array(
$title = t('@title [%language translation]', [
'@title' => $entity->getTranslation($langcode)->label(),
'%language' => $languages[$langcode]->getName(),
));
]);
$this->assertRaw($title);
}
}

View file

@ -14,7 +14,7 @@ class ThemeTest extends TaxonomyTestBase {
// Make sure we are using distinct default and administrative themes for
// the duration of these tests.
\Drupal::service('theme_handler')->install(array('bartik', 'seven'));
\Drupal::service('theme_handler')->install(['bartik', 'seven']);
$this->config('system.theme')
->set('default', 'bartik')
->set('admin', 'seven')
@ -22,14 +22,14 @@ class ThemeTest extends TaxonomyTestBase {
// Create and log in as a user who has permission to add and edit taxonomy
// terms and view the administrative theme.
$admin_user = $this->drupalCreateUser(array('administer taxonomy', 'view the administration theme'));
$admin_user = $this->drupalCreateUser(['administer taxonomy', 'view the administration theme']);
$this->drupalLogin($admin_user);
}
/**
* Test the theme used when adding, viewing and editing taxonomy terms.
*/
function testTaxonomyTermThemes() {
public function testTaxonomyTermThemes() {
// Adding a term to a vocabulary is considered an administrative action and
// should use the administrative theme.
$vocabulary = $this->createVocabulary();

View file

@ -16,9 +16,9 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
*
* @var array
*/
public static $testViews = array('test_taxonomy_node_term_data');
public static $testViews = ['test_taxonomy_node_term_data'];
function testViewsHandlerRelationshipNodeTermData() {
public function testViewsHandlerRelationshipNodeTermData() {
$view = Views::getView('test_taxonomy_node_term_data');
// Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
$expected = [
@ -30,16 +30,16 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
],
];
$this->assertIdentical($expected, $view->getDependencies());
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
$expected_result = array(
array(
$this->executeView($view, [$this->term1->id(), $this->term2->id()]);
$expected_result = [
[
'nid' => $this->nodes[1]->id(),
),
array(
],
[
'nid' => $this->nodes[0]->id(),
),
);
$column_map = array('nid' => 'nid');
],
];
$column_map = ['nid' => 'nid'];
$this->assertIdenticalResultset($view, $expected_result, $column_map);
// Change the view to test relation limited by vocabulary.
@ -51,7 +51,7 @@ class RelationshipNodeTermDataTest extends TaxonomyTestBase {
// Tests \Drupal\taxonomy\Plugin\views\relationship\NodeTermData::calculateDependencies().
$expected['config'][] = 'taxonomy.vocabulary.views_testing_tags';
$this->assertIdentical($expected, $view->getDependencies());
$this->executeView($view, array($this->term1->id(), $this->term2->id()));
$this->executeView($view, [$this->term1->id(), $this->term2->id()]);
$this->assertIdenticalResultset($view, $expected_result, $column_map);
}

View file

@ -16,7 +16,7 @@ class RelationshipRepresentativeNodeTest extends TaxonomyTestBase {
*
* @var array
*/
public static $testViews = array('test_groupwise_term');
public static $testViews = ['test_groupwise_term'];
/**
* Tests the relationship.
@ -24,17 +24,17 @@ class RelationshipRepresentativeNodeTest extends TaxonomyTestBase {
public function testRelationship() {
$view = Views::getView('test_groupwise_term');
$this->executeView($view);
$map = array('node_field_data_taxonomy_term_field_data_nid' => 'nid', 'tid' => 'tid');
$expected_result = array(
array(
$map = ['node_field_data_taxonomy_term_field_data_nid' => 'nid', 'tid' => 'tid'];
$expected_result = [
[
'nid' => $this->nodes[1]->id(),
'tid' => $this->term2->id(),
),
array(
],
[
'nid' => $this->nodes[1]->id(),
'tid' => $this->term1->id(),
),
);
],
];
$this->assertIdenticalResultset($view, $expected_result, $map);
}

View file

@ -19,7 +19,7 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
*
* @var array
*/
public static $testViews = array('taxonomy_default_argument_test');
public static $testViews = ['taxonomy_default_argument_test'];
/**
* Tests the relationship.
@ -37,7 +37,7 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
$view->setResponse($response);
$view->initHandlers();
$expected = implode(',', array($this->term1->id(), $this->term2->id()));
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
$view->destroy();
}
@ -68,7 +68,7 @@ class TaxonomyDefaultArgumentTest extends TaxonomyTestBase {
$view->setResponse($response);
$view->initHandlers();
$expected = implode(',', array($this->term1->id(), $this->term2->id()));
$expected = implode(',', [$this->term1->id(), $this->term2->id()]);
$this->assertEqual($expected, $view->argument['tid']->getDefaultArgument());
}

View file

@ -17,7 +17,7 @@ class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
*
* @var array
*/
public static $testViews = array('taxonomy_all_terms_test');
public static $testViews = ['taxonomy_all_terms_test'];
/**
* Tests the "all terms" field handler.

View file

@ -22,14 +22,14 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('language', 'taxonomy', 'taxonomy_test_views', 'text', 'views', 'node');
public static $modules = ['language', 'taxonomy', 'taxonomy_test_views', 'text', 'views', 'node'];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_field_filters');
public static $testViews = ['test_field_filters'];
/**
* The vocabulary used for creating terms.
@ -45,7 +45,7 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
*/
public $termNames = [];
function setUp() {
public function setUp() {
parent::setUp();
// Add two new languages.
@ -53,11 +53,11 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
ConfigurableLanguage::createFromLangcode('es')->save();
// Set up term names.
$this->termNames = array(
$this->termNames = [
'en' => 'Food in Paris',
'es' => 'Comida en Paris',
'fr' => 'Nouriture en Paris',
);
];
// Create a vocabulary.
$this->vocabulary = Vocabulary::create([
@ -67,11 +67,11 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
$this->vocabulary->save();
// Add a translatable field to the vocabulary.
$field = FieldStorageConfig::create(array(
$field = FieldStorageConfig::create([
'field_name' => 'field_foo',
'entity_type' => 'taxonomy_term',
'type' => 'text',
));
]);
$field->save();
FieldConfig::create([
'field_name' => 'field_foo',
@ -81,9 +81,9 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
])->save();
// Create term with translations.
$taxonomy = $this->createTermWithProperties(array('name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']));
foreach (array('es', 'fr') as $langcode) {
$translation = $taxonomy->addTranslation($langcode, array('name' => $this->termNames[$langcode]));
$taxonomy = $this->createTermWithProperties(['name' => $this->termNames['en'], 'langcode' => 'en', 'description' => $this->termNames['en'], 'field_foo' => $this->termNames['en']]);
foreach (['es', 'fr'] as $langcode) {
$translation = $taxonomy->addTranslation($langcode, ['name' => $this->termNames[$langcode]]);
$translation->description->value = $this->termNames[$langcode];
$translation->field_foo->value = $this->termNames[$langcode];
}
@ -91,7 +91,7 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
Views::viewsData()->clear();
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
$this->container->get('router.builder')->rebuild();
}
@ -101,27 +101,27 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
public function testFilters() {
// Test the name filter page, which filters for name contains 'Comida'.
// Should show just the Spanish translation, once.
$this->assertPageCounts('test-name-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida name filter');
$this->assertPageCounts('test-name-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida name filter');
// Test the description filter page, which filters for description contains
// 'Comida'. Should show just the Spanish translation, once.
$this->assertPageCounts('test-desc-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida description filter');
$this->assertPageCounts('test-desc-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida description filter');
// Test the field filter page, which filters for field_foo contains
// 'Comida'. Should show just the Spanish translation, once.
$this->assertPageCounts('test-field-filter', array('es' => 1, 'fr' => 0, 'en' => 0), 'Comida field filter');
$this->assertPageCounts('test-field-filter', ['es' => 1, 'fr' => 0, 'en' => 0], 'Comida field filter');
// Test the name Paris filter page, which filters for name contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-name-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris name filter');
$this->assertPageCounts('test-name-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris name filter');
// Test the description Paris page, which filters for description contains
// 'Paris'. Should show each translation, once.
$this->assertPageCounts('test-desc-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris description filter');
$this->assertPageCounts('test-desc-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris description filter');
// Test the field Paris filter page, which filters for field_foo contains
// 'Paris'. Should show each translation once.
$this->assertPageCounts('test-field-paris', array('es' => 1, 'fr' => 1, 'en' => 1), 'Paris field filter');
$this->assertPageCounts('test-field-paris', ['es' => 1, 'fr' => 1, 'en' => 1], 'Paris field filter');
}
@ -163,12 +163,12 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
$filter_formats = filter_formats();
$format = array_pop($filter_formats);
$properties += array(
$properties += [
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
'field_foo' => $this->randomMachineName(),
);
];
$term = Term::create([
'name' => $properties['name'],

View file

@ -17,9 +17,9 @@ class TaxonomyFieldTidTest extends TaxonomyTestBase {
*
* @var array
*/
public static $testViews = array('test_taxonomy_tid_field');
public static $testViews = ['test_taxonomy_tid_field'];
function testViewsHandlerTidField() {
public function testViewsHandlerTidField() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');

View file

@ -58,7 +58,7 @@ class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
$term->save();
$this->terms[$term->id()] = $term;
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
}
/**

View file

@ -24,7 +24,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_filter_taxonomy_index_tid', 'test_taxonomy_term_name');
public static $testViews = ['test_filter_taxonomy_index_tid', 'test_taxonomy_term_name'];
/**
* Modules to enable.
@ -71,7 +71,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
$term->save();
}
}
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
Vocabulary::create([
'vid' => 'empty_vocabulary',

View file

@ -18,14 +18,14 @@ class TaxonomyParentUITest extends UITestBase {
*
* @var array
*/
public static $testViews = array('test_taxonomy_parent');
public static $testViews = ['test_taxonomy_parent'];
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy', 'taxonomy_test_views');
public static $modules = ['taxonomy', 'taxonomy_test_views'];
/**
* {@inheritdoc}
@ -33,7 +33,7 @@ class TaxonomyParentUITest extends UITestBase {
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
}
/**

View file

@ -18,14 +18,14 @@ class TaxonomyRelationshipTest extends TaxonomyTestBase {
*
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = array();
protected $terms = [];
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_taxonomy_term_relationship');
public static $testViews = ['test_taxonomy_term_relationship'];
/**
* {@inheritdoc}

View file

@ -21,7 +21,7 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('taxonomy', 'views');
public static $modules = ['taxonomy', 'views'];
/**
* An user with permissions to administer taxonomy.
@ -51,23 +51,23 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
$this->fieldName1 = Unicode::strtolower($this->randomMachineName());
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
->setComponent($this->fieldName1, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
->setComponent($this->fieldName1, [
'type' => 'entity_reference_label',
))
])
->save();
}
@ -79,7 +79,7 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
$term = $this->createTerm();
// Post an article.
$edit = array();
$edit = [];
$edit['title[0][value]'] = $original_title = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit["{$this->fieldName1}[]"] = $term->id();
@ -90,7 +90,7 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
$this->assertText($term->label());
$this->assertText($node->label());
\Drupal::service('module_installer')->install(array('language', 'content_translation'));
\Drupal::service('module_installer')->install(['language', 'content_translation']);
$language = ConfigurableLanguage::createFromLangcode('ur');
$language->save();
// Enable translation for the article content type and ensure the change is

View file

@ -22,14 +22,14 @@ abstract class TaxonomyTestBase extends ViewTestBase {
*
* @var array
*/
public static $modules = array('taxonomy', 'taxonomy_test_views');
public static $modules = ['taxonomy', 'taxonomy_test_views'];
/**
* Stores the nodes used for the different tests.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $nodes = array();
protected $nodes = [];
/**
* The vocabulary used for creating terms.
@ -60,13 +60,13 @@ abstract class TaxonomyTestBase extends ViewTestBase {
$this->mockStandardInstall();
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
ViewTestData::createTestViews(get_class($this), ['taxonomy_test_views']);
}
$this->term1 = $this->createTerm();
$this->term2 = $this->createTerm();
$node = array();
$node = [];
$node['type'] = 'article';
$node['field_views_testing_tags'][]['target_id'] = $this->term1->id();
$node['field_views_testing_tags'][]['target_id'] = $this->term2->id();
@ -80,9 +80,9 @@ abstract class TaxonomyTestBase extends ViewTestBase {
* @see https://www.drupal.org/node/1708692
*/
protected function mockStandardInstall() {
$this->drupalCreateContentType(array(
$this->drupalCreateContentType([
'type' => 'article',
));
]);
// Create the vocabulary for the tag field.
$this->vocabulary = Vocabulary::create([
'name' => 'Views testing tags',
@ -91,32 +91,32 @@ abstract class TaxonomyTestBase extends ViewTestBase {
$this->vocabulary->save();
$field_name = 'field_' . $this->vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'entity_reference_autocomplete_tags',
'weight' => -4,
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'entity_reference_label',
'weight' => 10,
))
])
->save();
entity_get_display('node', 'article', 'teaser')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'entity_reference_label',
'weight' => 10,
))
])
->save();
}

View file

@ -0,0 +1,76 @@
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\taxonomy\Entity\Vocabulary;
/**
* Tests the vocabulary argument.
*
* @group taxonomy
*/
class TaxonomyVocabularyArgumentTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_argument_taxonomy_vocabulary'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* Vocabularies used for creating terms.
*
* @var \Drupal\taxonomy\VocabularyInterface[]
*/
protected $vocabularies;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add default vocabulary to list of vocabularies.
$this->vocabularies[] = $this->vocabulary;
// Create additional vocabulary.
$vocabulary = Vocabulary::create([
'name' => 'Views testing category',
'vid' => 'views_testing_category',
]);
$vocabulary->save();
$this->vocabularies[] = $vocabulary;
// Create some terms.
$this->terms[0] = $this->createTerm([
'name' => 'First',
'vid' => $this->vocabularies[0]->id(),
]);
$this->terms[1] = $this->createTerm([
'name' => 'Second',
'vid' => $this->vocabularies[1]->id(),
]);
}
/**
* Tests the vocabulary argument handler.
*
* @see Drupal\taxonomy\Plugin\views\argument\VocabularyVid
*/
public function testTermWithVocabularyArgument() {
$this->drupalGet('test_argument_taxonomy_vocabulary/' . $this->vocabularies[0]->id());
// First term should be present.
$this->assertText($this->terms[0]->label());
// Second term should not be present.
$this->assertNoText($this->terms[1]->label());
}
}

View file

@ -16,7 +16,7 @@ class TermNameFieldTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $testViews = array('test_taxonomy_term_name');
public static $testViews = ['test_taxonomy_term_name'];
/**
* Tests term name field plugin functionality.

View file

@ -31,30 +31,33 @@ class VocabularyUiTest extends TaxonomyTestBase {
/**
* Create, edit and delete a vocabulary via the user interface.
*/
function testVocabularyInterface() {
public function testVocabularyInterface() {
// Visit the main taxonomy administration page.
$this->drupalGet('admin/structure/taxonomy');
// Create a new vocabulary.
$this->clickLink(t('Add vocabulary'));
$edit = array();
$edit = [];
$vid = Unicode::strtolower($this->randomMachineName());
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$edit['vid'] = $vid;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertRaw(t('Created new vocabulary %name.', array('%name' => $edit['name'])), 'Vocabulary created successfully.');
$this->assertRaw(t('Created new vocabulary %name.', ['%name' => $edit['name']]), 'Vocabulary created successfully.');
// Edit the vocabulary.
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
$this->assertText($edit['name'], 'Vocabulary name found in the vocabulary overview listing.');
$this->assertText($edit['description'], 'Vocabulary description found in the vocabulary overview listing.');
$this->assertLinkByHref(Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $edit['vid']])->toString());
$this->clickLink(t('Edit vocabulary'));
$edit = array();
$edit = [];
$edit['name'] = $this->randomMachineName();
$edit['description'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy');
$this->assertText($edit['name'], 'Vocabulary found in the vocabulary overview listing.');
$this->assertText($edit['name'], 'Vocabulary name found in the vocabulary overview listing.');
$this->assertText($edit['description'], 'Vocabulary description found in the vocabulary overview listing.');
// Try to submit a vocabulary with a duplicate machine name.
$edit['vid'] = $vid;
@ -67,28 +70,28 @@ class VocabularyUiTest extends TaxonomyTestBase {
$this->assertText(t('The machine-readable name must contain only lowercase letters, numbers, and underscores.'));
// Ensure that vocabulary titles are escaped properly.
$edit = array();
$edit = [];
$edit['name'] = 'Don\'t Panic';
$edit['description'] = $this->randomMachineName();
$edit['vid'] = 'don_t_panic';
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$site_name = $this->config('system.site')->get('name');
$this->assertTitle(t('Don\'t Panic | @site-name', array('@site-name' => $site_name)), 'The page title contains the escaped character.');
$this->assertNoTitle(t('Don&#039;t Panic | @site-name', array('@site-name' => $site_name)), 'The page title does not contain an encoded character.');
$this->assertTitle(t('Don\'t Panic | @site-name', ['@site-name' => $site_name]), 'The page title contains the escaped character.');
$this->assertNoTitle(t('Don&#039;t Panic | @site-name', ['@site-name' => $site_name]), 'The page title does not contain an encoded character.');
}
/**
* Changing weights on the vocabulary overview with two or more vocabularies.
*/
function testTaxonomyAdminChangingWeights() {
public function testTaxonomyAdminChangingWeights() {
// Create some vocabularies.
for ($i = 0; $i < 10; $i++) {
$this->createVocabulary();
}
// Get all vocabularies and change their weights.
$vocabularies = Vocabulary::loadMultiple();
$edit = array();
$edit = [];
foreach ($vocabularies as $key => $vocabulary) {
$weight = -$vocabulary->get('weight');
$vocabularies[$key]->set('weight', $weight);
@ -110,7 +113,7 @@ class VocabularyUiTest extends TaxonomyTestBase {
/**
* Test the vocabulary overview with no vocabularies.
*/
function testTaxonomyAdminNoVocabularies() {
public function testTaxonomyAdminNoVocabularies() {
// Delete all vocabularies.
$vocabularies = Vocabulary::loadMultiple();
foreach ($vocabularies as $key => $vocabulary) {
@ -126,13 +129,13 @@ class VocabularyUiTest extends TaxonomyTestBase {
/**
* Deleting a vocabulary.
*/
function testTaxonomyAdminDeletingVocabulary() {
public function testTaxonomyAdminDeletingVocabulary() {
// Create a vocabulary.
$vid = Unicode::strtolower($this->randomMachineName());
$edit = array(
$edit = [
'name' => $this->randomMachineName(),
'vid' => $vid,
);
];
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
$this->assertText(t('Created new vocabulary'), 'New vocabulary was created.');
@ -144,12 +147,12 @@ class VocabularyUiTest extends TaxonomyTestBase {
// Delete the vocabulary.
$this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id());
$this->clickLink(t('Delete'));
$this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', array('%name' => $vocabulary->label())), '[confirm deletion] Asks for confirmation.');
$this->assertRaw(t('Are you sure you want to delete the vocabulary %name?', ['%name' => $vocabulary->label()]), '[confirm deletion] Asks for confirmation.');
$this->assertText(t('Deleting a vocabulary will delete all the terms in it. This action cannot be undone.'), '[confirm deletion] Inform that all terms will be deleted.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted vocabulary %name.', array('%name' => $vocabulary->label())), 'Vocabulary deleted.');
$this->assertRaw(t('Deleted vocabulary %name.', ['%name' => $vocabulary->label()]), 'Vocabulary deleted.');
$this->container->get('entity.manager')->getStorage('taxonomy_vocabulary')->resetCache();
$this->assertFalse(Vocabulary::load($vid), 'Vocabulary not found.');
}

View file

@ -52,59 +52,59 @@ class VocabularyForm extends BundleEntityFormBase {
$form['#title'] = $this->t('Edit vocabulary');
}
$form['name'] = array(
$form['name'] = [
'#type' => 'textfield',
'#title' => $this->t('Name'),
'#default_value' => $vocabulary->label(),
'#maxlength' => 255,
'#required' => TRUE,
);
$form['vid'] = array(
];
$form['vid'] = [
'#type' => 'machine_name',
'#default_value' => $vocabulary->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => array(
'exists' => array($this, 'exists'),
'source' => array('name'),
),
);
$form['description'] = array(
'#machine_name' => [
'exists' => [$this, 'exists'],
'source' => ['name'],
],
];
$form['description'] = [
'#type' => 'textfield',
'#title' => $this->t('Description'),
'#default_value' => $vocabulary->getDescription(),
);
];
// $form['langcode'] is not wrapped in an
// if ($this->moduleHandler->moduleExists('language')) check because the
// language_select form element works also without the language module being
// installed. https://www.drupal.org/node/1749954 documents the new element.
$form['langcode'] = array(
$form['langcode'] = [
'#type' => 'language_select',
'#title' => $this->t('Vocabulary language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $vocabulary->language()->getId(),
);
];
if ($this->moduleHandler->moduleExists('language')) {
$form['default_terms_language'] = array(
$form['default_terms_language'] = [
'#type' => 'details',
'#title' => $this->t('Terms language'),
'#open' => TRUE,
);
$form['default_terms_language']['default_language'] = array(
];
$form['default_terms_language']['default_language'] = [
'#type' => 'language_configuration',
'#entity_information' => array(
'#entity_information' => [
'entity_type' => 'taxonomy_term',
'bundle' => $vocabulary->id(),
),
],
'#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary->id()),
);
];
}
// Set the hierarchy to "multiple parents" by default. This simplifies the
// vocabulary form and standardizes the term form.
$form['hierarchy'] = array(
$form['hierarchy'] = [
'#type' => 'value',
'#value' => '0',
);
];
$form = parent::form($form, $form_state);
return $this->protectBundleIdElement($form);
@ -123,14 +123,14 @@ class VocabularyForm extends BundleEntityFormBase {
$edit_link = $this->entity->link($this->t('Edit'));
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created new vocabulary %name.', array('%name' => $vocabulary->label())));
$this->logger('taxonomy')->notice('Created new vocabulary %name.', array('%name' => $vocabulary->label(), 'link' => $edit_link));
drupal_set_message($this->t('Created new vocabulary %name.', ['%name' => $vocabulary->label()]));
$this->logger('taxonomy')->notice('Created new vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
$form_state->setRedirectUrl($vocabulary->urlInfo('overview-form'));
break;
case SAVED_UPDATED:
drupal_set_message($this->t('Updated vocabulary %name.', array('%name' => $vocabulary->label())));
$this->logger('taxonomy')->notice('Updated vocabulary %name.', array('%name' => $vocabulary->label(), 'link' => $edit_link));
drupal_set_message($this->t('Updated vocabulary %name.', ['%name' => $vocabulary->label()]));
$this->logger('taxonomy')->notice('Updated vocabulary %name.', ['%name' => $vocabulary->label(), 'link' => $edit_link]);
$form_state->setRedirectUrl($vocabulary->urlInfo('collection'));
break;
}

View file

@ -36,16 +36,16 @@ class VocabularyListBuilder extends DraggableListBuilder {
$operations['edit']['title'] = t('Edit vocabulary');
}
$operations['list'] = array(
$operations['list'] = [
'title' => t('List terms'),
'weight' => 0,
'url' => $entity->urlInfo('overview-form'),
);
$operations['add'] = array(
];
$operations['add'] = [
'title' => t('Add terms'),
'weight' => 10,
'url' => Url::fromRoute('entity.taxonomy_term.add_form', ['taxonomy_vocabulary' => $entity->id()]),
);
];
unset($operations['delete']);
return $operations;
@ -56,6 +56,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
*/
public function buildHeader() {
$header['label'] = t('Vocabulary name');
$header['description'] = t('Description');
return $header + parent::buildHeader();
}
@ -64,6 +65,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['description']['data'] = ['#markup' => $entity->getDescription()];
return $row + parent::buildRow($entity);
}
@ -78,7 +80,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>.', [':link' => \Drupal::url('entity.taxonomy_vocabulary.add_form')]);
return $build;
}
@ -87,7 +89,7 @@ class VocabularyListBuilder extends DraggableListBuilder {
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = parent::buildForm($form, $form_state);
$form['vocabularies']['#attributes'] = array('id' => 'taxonomy');
$form['vocabularies']['#attributes'] = ['id' => 'taxonomy'];
$form['actions']['submit']['#value'] = t('Save');
return $form;

View file

@ -21,7 +21,7 @@ class VocabularyStorage extends ConfigEntityStorage implements VocabularyStorage
* {@inheritdoc}
*/
public function getToplevelTids($vids) {
return db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid IN ( :vids[] ) AND th.parent = 0', array(':vids[]' => $vids))->fetchCol();
return db_query('SELECT t.tid FROM {taxonomy_term_data} t INNER JOIN {taxonomy_term_hierarchy} th ON th.tid = t.tid WHERE t.vid IN ( :vids[] ) AND th.parent = 0', [':vids[]' => $vids])->fetchCol();
}
}

View file

@ -47,23 +47,23 @@ const TAXONOMY_HIERARCHY_MULTIPLE = 2;
function taxonomy_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.taxonomy':
$field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', array('name' => 'field_ui')) : '#';
$field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? \Drupal::url('help.page', ['name' => 'field_ui']) : '#';
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', array(':permissions' => \Drupal::url('user.admin_permissions', array(), array('fragment' => 'module-taxonomy')))) . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', array(':taxonomy' => 'https://www.drupal.org/documentation/modules/taxonomy/')) . '</p>';
$output .= '<p>' . t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', [':permissions' => \Drupal::url('user.admin_permissions', [], ['fragment' => 'module-taxonomy'])]) . '</p>';
$output .= '<p>' . t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', [':taxonomy' => 'https://www.drupal.org/documentation/modules/taxonomy/']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Managing vocabularies') . '</dt>';
$output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', array(':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection'), ':field_ui' => $field_ui_url)) . '</dd>';
$output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', [':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection'), ':field_ui' => $field_ui_url]) . '</dd>';
$output .= '<dt>' . t('Managing terms') . '</dt>';
$output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', array(':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection'))) . ' </dd>';
$output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', [':taxonomy_admin' => \Drupal::url('entity.taxonomy_vocabulary.collection')]) . ' </dd>';
$output .= '<dt>' . t('Classifying entity content') . '</dt>';
$output .= '<dd>' . t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', array(':field_ui' => $field_ui_url, ':field' => \Drupal::url('help.page', array('name' => 'field')), ':entity_reference' => \Drupal::url('help.page', array('name' => 'entity_reference')))) . '</dd>';
$output .= '<dd>' . t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', [':field_ui' => $field_ui_url, ':field' => \Drupal::url('help.page', ['name' => 'field']), ':entity_reference' => \Drupal::url('help.page', ['name' => 'entity_reference'])]) . '</dd>';
$output .= '<dt>' . t('Adding new terms during content creation') . '</dt>';
$output .= '<dd>' . t('Allowing users to add new terms gradually builds a vocabulary as content is added and edited. Users can add new terms if either of the two <em>Autocomplete</em> widgets is chosen for the Taxonomy term reference field in the <em>Manage form display</em> page for the field. You will also need to enable the <em>Create referenced entities if they don\'t already exist</em> option, and restrict the field to one vocabulary.') . '</dd>';
$output .= '<dt>' . t('Configuring displays and form displays') . '</dt>';
$output .= '<dd>' . t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', array(':entity_reference' => \Drupal::url('help.page', array('name' => 'entity_reference')))) . '</li>';
$output .= '<dd>' . t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', [':entity_reference' => \Drupal::url('help.page', ['name' => 'entity_reference'])]) . '</li>';
$output .= '</ul>';
$output .= '</dd>';
$output .= '</dl>';
@ -77,11 +77,11 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) {
$vocabulary = $route_match->getParameter('taxonomy_vocabulary');
switch ($vocabulary->getHierarchy()) {
case VocabularyInterface::HIERARCHY_DISABLED:
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '</p>';
return '<p>' . t('You can reorganize the terms in %capital_name using their drag-and-drop handles, and group terms under a parent term by sliding them under and to the right of the parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
case VocabularyInterface::HIERARCHY_SINGLE:
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label())) . '</p>';
return '<p>' . t('%capital_name contains terms grouped under parent terms. You can reorganize the terms in %capital_name using their drag-and-drop handles.', ['%capital_name' => Unicode::ucfirst($vocabulary->label()), '%name' => $vocabulary->label()]) . '</p>';
case VocabularyInterface::HIERARCHY_MULTIPLE:
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', array('%capital_name' => Unicode::ucfirst($vocabulary->label()))) . '</p>';
return '<p>' . t('%capital_name contains terms with multiple parents. Drag and drop of terms with multiple parents is not supported, but you can re-enable drag-and-drop support by editing each term to include only a single parent.', ['%capital_name' => Unicode::ucfirst($vocabulary->label())]) . '</p>';
}
}
}
@ -90,9 +90,9 @@ function taxonomy_help($route_name, RouteMatchInterface $route_match) {
* Entity URI callback.
*/
function taxonomy_term_uri($term) {
return new Url('entity.taxonomy_term.canonical', array(
return new Url('entity.taxonomy_term.canonical', [
'taxonomy_term' => $term->id(),
));
]);
}
/**
@ -103,24 +103,24 @@ function taxonomy_page_attachments_alter(array &$page) {
if ($route_match->getRouteName() == 'entity.taxonomy_term.canonical' && ($term = $route_match->getParameter('taxonomy_term')) && $term instanceof TermInterface) {
foreach ($term->uriRelationships() as $rel) {
// Set the URI relationships, like canonical.
$page['#attached']['html_head_link'][] = array(
array(
$page['#attached']['html_head_link'][] = [
[
'rel' => $rel,
'href' => $term->url($rel),
),
],
TRUE,
);
];
// Set the term path as the canonical URL to prevent duplicate content.
if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink.
$page['#attached']['html_head_link'][] = array(
array(
$page['#attached']['html_head_link'][] = [
[
'rel' => 'shortlink',
'href' => $term->url($rel, array('alias' => TRUE)),
),
'href' => $term->url($rel, ['alias' => TRUE]),
],
TRUE,
);
];
}
}
}
@ -130,11 +130,11 @@ function taxonomy_page_attachments_alter(array &$page) {
* Implements hook_theme().
*/
function taxonomy_theme() {
return array(
'taxonomy_term' => array(
return [
'taxonomy_term' => [
'render element' => 'elements',
),
);
],
];
}
/**
@ -223,7 +223,7 @@ function taxonomy_term_view_multiple(array $terms, $view_mode = 'full', $langcod
* Implements hook_theme_suggestions_HOOK().
*/
function taxonomy_theme_suggestions_taxonomy_term(array $variables) {
$suggestions = array();
$suggestions = [];
/** @var \Drupal\taxonomy\TermInterface $term */
$term = $variables['elements']['#taxonomy_term'];
@ -261,7 +261,7 @@ function template_preprocess_taxonomy_term(&$variables) {
$variables['page'] = $variables['view_mode'] == 'full' && taxonomy_term_is_page($term);
// Helpful $content variable for templates.
$variables['content'] = array();
$variables['content'] = [];
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
@ -307,7 +307,7 @@ function taxonomy_vocabulary_get_names() {
$names = &drupal_static(__FUNCTION__);
if (!isset($names)) {
$names = array();
$names = [];
$config_names = \Drupal::configFactory()->listAll('taxonomy.vocabulary.');
foreach ($config_names as $config_name) {
$id = substr($config_name, strlen('taxonomy.vocabulary.'));
@ -333,7 +333,7 @@ function taxonomy_vocabulary_get_names() {
* An array of matching term objects.
*/
function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
$values = array('name' => trim($name));
$values = ['name' => trim($name)];
if (isset($vocabulary)) {
$vocabularies = taxonomy_vocabulary_get_names();
if (isset($vocabularies[$vocabulary])) {
@ -341,7 +341,7 @@ function taxonomy_term_load_multiple_by_name($name, $vocabulary = NULL) {
}
else {
// Return an empty array when filtering by a non-existing vocabulary.
return array();
return [];
}
}
return entity_load_multiple_by_properties('taxonomy_term', $values);
@ -436,7 +436,7 @@ function taxonomy_term_load($tid) {
* @see \Drupal\Component\Utility\Tags::explode()
*/
function taxonomy_implode_tags($tags, $vid = NULL) {
$typed_tags = array();
$typed_tags = [];
foreach ($tags as $tag) {
// Extract terms belonging to the vocabulary in question.
if (!isset($vid) || $tag->bundle() == $vid) {
@ -510,7 +510,7 @@ function taxonomy_build_node_index($node) {
// We only maintain the taxonomy index for published nodes.
if ($status && $node->isDefaultRevision()) {
// Collect a unique list of all the term IDs from all node fields.
$tid_all = array();
$tid_all = [];
$entity_reference_class = 'Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem';
foreach ($node->getFieldDefinitions() as $field) {
$field_name = $field->getName();
@ -530,8 +530,8 @@ function taxonomy_build_node_index($node) {
if (!empty($tid_all)) {
foreach ($tid_all as $tid) {
db_merge('taxonomy_index')
->key(array('nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()))
->fields(array('sticky' => $sticky, 'created' => $node->getCreatedTime()))
->key(['nid' => $node->id(), 'tid' => $tid, 'status' => $node->isPublished()])
->fields(['sticky' => $sticky, 'created' => $node->getCreatedTime()])
->execute();
}
}

View file

@ -12,80 +12,80 @@ use Drupal\taxonomy\Entity\Vocabulary;
* Implements hook_token_info().
*/
function taxonomy_token_info() {
$types['term'] = array(
$types['term'] = [
'name' => t("Taxonomy terms"),
'description' => t("Tokens related to taxonomy terms."),
'needs-data' => 'term',
);
$types['vocabulary'] = array(
];
$types['vocabulary'] = [
'name' => t("Vocabularies"),
'description' => t("Tokens related to taxonomy vocabularies."),
'needs-data' => 'vocabulary',
);
];
// Taxonomy term related variables.
$term['tid'] = array(
$term['tid'] = [
'name' => t("Term ID"),
'description' => t("The unique ID of the taxonomy term."),
);
$term['name'] = array(
];
$term['name'] = [
'name' => t("Name"),
'description' => t("The name of the taxonomy term."),
);
$term['description'] = array(
];
$term['description'] = [
'name' => t("Description"),
'description' => t("The optional description of the taxonomy term."),
);
$term['node-count'] = array(
];
$term['node-count'] = [
'name' => t("Node count"),
'description' => t("The number of nodes tagged with the taxonomy term."),
);
$term['url'] = array(
];
$term['url'] = [
'name' => t("URL"),
'description' => t("The URL of the taxonomy term."),
);
];
// Taxonomy vocabulary related variables.
$vocabulary['vid'] = array(
$vocabulary['vid'] = [
'name' => t("Vocabulary ID"),
'description' => t("The unique ID of the taxonomy vocabulary."),
);
$vocabulary['name'] = array(
];
$vocabulary['name'] = [
'name' => t("Name"),
'description' => t("The name of the taxonomy vocabulary."),
);
$vocabulary['description'] = array(
];
$vocabulary['description'] = [
'name' => t("Description"),
'description' => t("The optional description of the taxonomy vocabulary."),
);
$vocabulary['node-count'] = array(
];
$vocabulary['node-count'] = [
'name' => t("Node count"),
'description' => t("The number of nodes tagged with terms belonging to the taxonomy vocabulary."),
);
$vocabulary['term-count'] = array(
];
$vocabulary['term-count'] = [
'name' => t("Term count"),
'description' => t("The number of terms belonging to the taxonomy vocabulary."),
);
];
// Chained tokens for taxonomies
$term['vocabulary'] = array(
$term['vocabulary'] = [
'name' => t("Vocabulary"),
'description' => t("The vocabulary the taxonomy term belongs to."),
'type' => 'vocabulary',
);
$term['parent'] = array(
];
$term['parent'] = [
'name' => t("Parent term"),
'description' => t("The parent term of the taxonomy term, if one exists."),
'type' => 'term',
);
];
return array(
return [
'types' => $types,
'tokens' => array(
'tokens' => [
'term' => $term,
'vocabulary' => $vocabulary,
),
);
],
];
}
/**
@ -94,7 +94,7 @@ function taxonomy_token_info() {
function taxonomy_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$token_service = \Drupal::token();
$replacements = array();
$replacements = [];
$taxonomy_storage = \Drupal::entityManager()->getStorage('taxonomy_term');
if ($type == 'term' && !empty($data['term'])) {
$term = $data['term'];
@ -116,7 +116,7 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable
break;
case 'url':
$replacements[$original] = $term->url('canonical', array('absolute' => TRUE));
$replacements[$original] = $term->url('canonical', ['absolute' => TRUE]);
break;
case 'node-count':
@ -145,12 +145,12 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable
if ($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'vocabulary')) {
$vocabulary = Vocabulary::load($term->bundle());
$replacements += $token_service->generate('vocabulary', $vocabulary_tokens, array('vocabulary' => $vocabulary), $options, $bubbleable_metadata);
$replacements += $token_service->generate('vocabulary', $vocabulary_tokens, ['vocabulary' => $vocabulary], $options, $bubbleable_metadata);
}
if (($vocabulary_tokens = $token_service->findWithPrefix($tokens, 'parent')) && $parents = $taxonomy_storage->loadParents($term->id())) {
$parent = array_pop($parents);
$replacements += $token_service->generate('term', $vocabulary_tokens, array('term' => $parent), $options, $bubbleable_metadata);
$replacements += $token_service->generate('term', $vocabulary_tokens, ['term' => $parent], $options, $bubbleable_metadata);
}
}

View file

@ -11,44 +11,44 @@ use Drupal\field\FieldStorageConfigInterface;
* Implements hook_views_data_alter().
*/
function taxonomy_views_data_alter(&$data) {
$data['node_field_data']['term_node_tid'] = array(
$data['node_field_data']['term_node_tid'] = [
'title' => t('Taxonomy terms on node'),
'help' => t('Relate nodes to taxonomy terms, specifying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'),
'relationship' => array(
'relationship' => [
'id' => 'node_term_data',
'label' => t('term'),
'base' => 'taxonomy_term_field_data',
),
'field' => array(
],
'field' => [
'title' => t('All taxonomy terms'),
'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'),
'id' => 'taxonomy_index_tid',
'no group by' => TRUE,
'click sortable' => FALSE,
),
);
],
];
$data['node_field_data']['term_node_tid_depth'] = array(
$data['node_field_data']['term_node_tid_depth'] = [
'help' => t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.'),
'real field' => 'nid',
'argument' => array(
'argument' => [
'title' => t('Has taxonomy term ID (with depth)'),
'id' => 'taxonomy_index_tid_depth',
'accept depth modifier' => TRUE,
),
'filter' => array(
],
'filter' => [
'title' => t('Has taxonomy terms (with depth)'),
'id' => 'taxonomy_index_tid_depth',
),
);
],
];
$data['node_field_data']['term_node_tid_depth_modifier'] = array(
$data['node_field_data']['term_node_tid_depth_modifier'] = [
'title' => t('Has taxonomy term ID depth modifier'),
'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.'),
'argument' => array(
'argument' => [
'id' => 'taxonomy_index_tid_depth_modifier',
),
);
],
];
}
/**

View file

@ -0,0 +1,174 @@
langcode: en
status: true
dependencies:
module:
- taxonomy
- user
id: test_argument_taxonomy_vocabulary
label: test_argument_taxonomy_vocabulary
module: views
description: ''
tag: ''
base_table: taxonomy_term_field_data
base_field: tid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
offset: 0
style:
type: default
row:
type: 'entity:taxonomy_term'
fields:
name:
id: name
table: taxonomy_term_field_data
field: name
entity_type: taxonomy_term
entity_field: name
label: ''
alter:
alter_text: false
make_link: false
absolute: false
trim: false
word_boundary: false
ellipsis: false
strip_tags: false
html: false
hide_empty: false
empty_zero: false
type: string
settings:
link_to_entity: true
plugin_id: term_name
relationship: none
group_type: group
admin_label: ''
exclude: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_alter_empty: true
click_sort_column: value
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
convert_spaces: false
filters: { }
sorts: { }
title: ''
header: { }
footer: { }
empty: { }
relationships: { }
arguments:
vid:
id: vid
table: taxonomy_term_field_data
field: vid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
entity_type: taxonomy_term
entity_field: vid
plugin_id: vocabulary_vid
display_extenders: { }
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user.permissions
tags: { }
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 1
display_options:
display_extenders: { }
path: test_argument_taxonomy_vocabulary
cache_metadata:
max-age: -1
contexts:
- 'languages:language_content'
- 'languages:language_interface'
- url
- user.permissions
tags: { }

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
/**
* Verifies operation of a taxonomy-based Entity Query.
@ -25,8 +25,8 @@ class EfqTest extends TaxonomyTestBase {
/**
* Tests that a basic taxonomy entity query works.
*/
function testTaxonomyEfq() {
$terms = array();
public function testTaxonomyEfq() {
$terms = [];
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($this->vocabulary);
$terms[$term->id()] = $term;
@ -35,17 +35,17 @@ class EfqTest extends TaxonomyTestBase {
sort($result);
$this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.');
$tid = reset($result);
$ids = (object) array(
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $this->vocabulary->id(),
);
];
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
// Create a second vocabulary and five more terms.
$vocabulary2 = $this->createVocabulary();
$terms2 = array();
$terms2 = [];
for ($i = 0; $i < 5; $i++) {
$term = $this->createTerm($vocabulary2);
$terms2[$term->id()] = $term;
@ -55,13 +55,13 @@ class EfqTest extends TaxonomyTestBase {
->condition('vid', $vocabulary2->id())
->execute();
sort($result);
$this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', array('%name' => $vocabulary2->label())));
$this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', ['%name' => $vocabulary2->label()]));
$tid = reset($result);
$ids = (object) array(
$ids = (object) [
'entity_type' => 'taxonomy_term',
'entity_id' => $tid,
'bundle' => $vocabulary2->id(),
);
];
$term = _field_create_entity_from_ids($ids);
$this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.');
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@ -18,7 +18,7 @@ class LegacyTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('node', 'datetime');
public static $modules = ['node', 'datetime'];
protected function setUp() {
parent::setUp();
@ -31,18 +31,18 @@ class LegacyTest extends TaxonomyTestBase {
$vocabulary->save();
$field_name = 'field_' . $vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$vocabulary->id() => $vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($field_name, array(
->setComponent($field_name, [
'type' => 'entity_reference_autocomplete_tags',
))
])
->save();
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy', 'administer nodes', 'bypass node access']));
@ -51,10 +51,10 @@ class LegacyTest extends TaxonomyTestBase {
/**
* Test taxonomy functionality with nodes prior to 1970.
*/
function testTaxonomyLegacyNode() {
public function testTaxonomyLegacyNode() {
// Posts an article with a taxonomy term and a date prior to 1970.
$date = new DrupalDateTime('1969-01-01 00:00:00');
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['created[0][value][date]'] = $date->format('Y-m-d');
$edit['created[0][value][time]'] = $date->format('H:i:s');

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\taxonomy\Entity\Term;
@ -20,7 +20,7 @@ class LoadMultipleTest extends TaxonomyTestBase {
* Create a vocabulary and some taxonomy terms, ensuring they're loaded
* correctly using entity_load_multiple().
*/
function testTaxonomyTermMultipleLoad() {
public function testTaxonomyTermMultipleLoad() {
// Create a vocabulary.
$vocabulary = $this->createVocabulary();
@ -31,9 +31,9 @@ class LoadMultipleTest extends TaxonomyTestBase {
$this->createTerm($vocabulary);
}
// Load the terms from the vocabulary.
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
$terms = entity_load_multiple_by_properties('taxonomy_term', ['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.', ['@count' => $count]));
// Load the same terms again by tid.
$terms2 = Term::loadMultiple(array_keys($terms));
@ -47,13 +47,13 @@ class LoadMultipleTest extends TaxonomyTestBase {
$this->assertFalse($deleted_term);
// Load terms from the vocabulary by vid.
$terms3 = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
$terms3 = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
$this->assertEqual(count($terms3), 4, 'Correct number of terms were loaded.');
$this->assertFalse(isset($terms3[$deleted->id()]));
// Create a single term and load it by name.
$term = $this->createTerm($vocabulary);
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', array('name' => $term->getName()));
$loaded_terms = entity_load_multiple_by_properties('taxonomy_term', ['name' => $term->getName()]);
$this->assertEqual(count($loaded_terms), 1, 'One term was loaded.');
$loaded_term = reset($loaded_terms);
$this->assertEqual($term->id(), $loaded_term->id(), 'Term loaded by name successfully.');

View file

@ -0,0 +1,37 @@
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
/**
* Provides common helper methods for Taxonomy module tests.
*/
abstract class TaxonomyTestBase extends BrowserTestBase {
use TaxonomyTestTrait;
use EntityReferenceTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['taxonomy', 'block'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
// Create Basic page and Article node types.
if ($this->profile != 'standard') {
$this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
}
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase;
use Drupal\taxonomy\Entity\Vocabulary;
@ -16,7 +16,7 @@ class TermCacheTagsTest extends EntityWithUriCacheTagsTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field\Entity\FieldConfig;
@ -26,7 +26,7 @@ class TermEntityReferenceTest extends TaxonomyTestBase {
* field to limit the target vocabulary to one of them, ensuring that
* the restriction applies.
*/
function testSelectionTestVocabularyRestriction() {
public function testSelectionTestVocabularyRestriction() {
// Create two vocabularies.
$vocabulary = $this->createVocabulary();
@ -37,41 +37,41 @@ class TermEntityReferenceTest extends TaxonomyTestBase {
// Create an entity reference field.
$field_name = 'taxonomy_' . $vocabulary->id();
$field_storage = FieldStorageConfig::create(array(
$field_storage = FieldStorageConfig::create([
'field_name' => $field_name,
'entity_type' => 'entity_test',
'translatable' => FALSE,
'settings' => array(
'settings' => [
'target_type' => 'taxonomy_term',
),
],
'type' => 'entity_reference',
'cardinality' => 1,
));
]);
$field_storage->save();
$field = FieldConfig::create(array(
$field = FieldConfig::create([
'field_storage' => $field_storage,
'entity_type' => 'entity_test',
'bundle' => 'test_bundle',
'settings' => array(
'settings' => [
'handler' => 'default',
'handler_settings' => array(
'handler_settings' => [
// Restrict selection of terms to a single vocabulary.
'target_bundles' => array(
'target_bundles' => [
$vocabulary->id() => $vocabulary->id(),
),
),
),
));
],
],
],
]);
$field->save();
$handler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
$result = $handler->getReferenceableEntities();
$expected_result = array(
$vocabulary->id() => array(
$expected_result = [
$vocabulary->id() => [
$term->id() => $term->getName(),
),
);
],
];
$this->assertIdentical($result, $expected_result, 'Terms selection restricted to a single vocabulary.');
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
@ -17,7 +17,7 @@ class TermIndexTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('views');
public static $modules = ['views'];
/**
* Vocabulary for testing.
@ -50,51 +50,51 @@ class TermIndexTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->fieldName1 = Unicode::strtolower($this->randomMachineName());
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $this->fieldName1, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
->setComponent($this->fieldName1, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName1, array(
->setComponent($this->fieldName1, [
'type' => 'entity_reference_label',
))
])
->save();
$this->fieldName2 = Unicode::strtolower($this->randomMachineName());
$this->createEntityReferenceField('node', 'article', $this->fieldName2, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName2, array(
->setComponent($this->fieldName2, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName2, array(
->setComponent($this->fieldName2, [
'type' => 'entity_reference_label',
))
])
->save();
}
/**
* Tests that the taxonomy index is maintained properly.
*/
function testTaxonomyIndex() {
public function testTaxonomyIndex() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Create terms in the vocabulary.
$term_1 = $this->createTerm($this->vocabulary);
$term_2 = $this->createTerm($this->vocabulary);
// Post an article.
$edit = array();
$edit = [];
$edit['title[0][value]'] = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomMachineName();
$edit["{$this->fieldName1}[]"] = $term_1->id();
@ -103,10 +103,10 @@ class TermIndexTest extends TaxonomyTestBase {
// Check that the term is indexed, and only once.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
// Update the article to change one term.
@ -114,15 +114,15 @@ class TermIndexTest extends TaxonomyTestBase {
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that both terms are indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
@ -130,19 +130,19 @@ class TermIndexTest extends TaxonomyTestBase {
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Check that only one term is indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Redo the above tests without interface.
$node_storage->resetCache(array($node->id()));
$node_storage->resetCache([$node->id()]);
$node = $node_storage->load($node->id());
$node->title = $this->randomMachineName();
@ -150,58 +150,58 @@ class TermIndexTest extends TaxonomyTestBase {
$node->save();
// Check that the index was not changed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 1 is not indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed once.');
// Update the article to change one term.
$node->{$this->fieldName1} = array(array('target_id' => $term_1->id()));
$node->{$this->fieldName1} = [['target_id' => $term_1->id()]];
$node->save();
// Check that both terms are indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 2 is indexed.');
// Update the article to change another term.
$node->{$this->fieldName2} = array(array('target_id' => $term_1->id()));
$node->{$this->fieldName2} = [['target_id' => $term_1->id()]];
$node->save();
// Check that only one term is indexed.
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_1->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(1, $index_count, 'Term 1 is indexed once.');
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', array(
$index_count = db_query('SELECT COUNT(*) FROM {taxonomy_index} WHERE nid = :nid AND tid = :tid', [
':nid' => $node->id(),
':tid' => $term_2->id(),
))->fetchField();
])->fetchField();
$this->assertEqual(0, $index_count, 'Term 2 is not indexed.');
}
/**
* Tests that there is a link to the parent term on the child term page.
*/
function testTaxonomyTermHierarchyBreadcrumbs() {
public function testTaxonomyTermHierarchyBreadcrumbs() {
// Create two taxonomy terms and set term2 as the parent of term1.
$term1 = $this->createTerm($this->vocabulary);
$term2 = $this->createTerm($this->vocabulary);
$term1->parent = array($term2->id());
$term1->parent = [$term2->id()];
$term1->save();
// Verify that the page breadcrumbs include a link to the parent term.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
@ -12,7 +12,7 @@ use Drupal\language\Entity\ConfigurableLanguage;
*/
class TermLanguageTest extends TaxonomyTestBase {
public static $modules = array('language');
public static $modules = ['language'];
/**
* Vocabulary for testing.
@ -31,19 +31,19 @@ class TermLanguageTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
// Add some custom languages.
foreach (array('aa', 'bb', 'cc') as $language_code) {
ConfigurableLanguage::create(array(
foreach (['aa', 'bb', 'cc'] as $language_code) {
ConfigurableLanguage::create([
'id' => $language_code,
'label' => $this->randomMachineName(),
))->save();
])->save();
}
}
function testTermLanguage() {
public function testTermLanguage() {
// Configure the vocabulary to not hide the language selector.
$edit = array(
$edit = [
'default_language[language_alterable]' => TRUE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
// Add a term.
@ -51,10 +51,10 @@ class TermLanguageTest extends TaxonomyTestBase {
// Check that we have the language selector.
$this->assertField('edit-langcode-0-value', t('The language selector field was found on the page.'));
// Submit the term.
$edit = array(
$edit = [
'name[0][value]' => $this->randomMachineName(),
'langcode[0][value]' => 'aa',
);
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
@ -73,22 +73,22 @@ class TermLanguageTest extends TaxonomyTestBase {
$this->assertOptionSelected('edit-langcode-0-value', $edit['langcode[0][value]'], 'The term language was correctly selected.');
}
function testDefaultTermLanguage() {
public function testDefaultTermLanguage() {
// Configure the vocabulary to not hide the language selector, and make the
// default language of the terms fixed.
$edit = array(
$edit = [
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'bb', 'The expected langcode was selected.');
// Make the default language of the terms to be the current interface.
$edit = array(
$edit = [
'default_language[langcode]' => 'current_interface',
'default_language[language_alterable]' => TRUE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('aa/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'aa', "The expected langcode, 'aa', was selected.");
@ -98,13 +98,46 @@ class TermLanguageTest extends TaxonomyTestBase {
// Change the default language of the site and check if the default terms
// language is still correctly selected.
$this->config('system.site')->set('default_langcode', 'cc')->save();
$edit = array(
$edit = [
'default_language[langcode]' => LanguageInterface::LANGCODE_SITE_DEFAULT,
'default_language[language_alterable]' => TRUE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
$this->assertOptionSelected('edit-langcode-0-value', 'cc', "The expected langcode, 'cc', was selected.");
}
/**
* Tests that translated terms are displayed correctly on the term overview.
*/
public function testTermTranslatedOnOverviewPage() {
// Configure the vocabulary to not hide the language selector.
$edit = [
'default_language[language_alterable]' => TRUE,
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $this->vocabulary->id(), $edit, t('Save'));
// Add a term.
$this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/add');
// Submit the term.
$edit = [
'name[0][value]' => $this->randomMachineName(),
'langcode[0][value]' => 'aa',
];
$this->drupalPostForm(NULL, $edit, t('Save'));
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
$term = reset($terms);
// Add a translation for that term.
$translated_title = $this->randomMachineName();
$term->addTranslation('bb', [
'name' => $translated_title,
]);
$term->save();
// Overview page in the other language shows the translated term
$this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
$this->assertPattern('|<a[^>]*>' . $translated_title . '</a>|', 'The term language is correct');
}
}

View file

@ -1,8 +1,9 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait;
/**
* Tests the translation of taxonomy terms field on nodes.
@ -39,7 +40,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('language', 'content_translation', 'taxonomy');
public static $modules = ['language', 'content_translation', 'taxonomy'];
protected function setUp() {
parent::setUp();
@ -78,7 +79,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
'value' => $this->randomMachineName(),
'format' => 'basic_html'
]],
$this->termFieldName => array(array('target_id' => $this->term->id())),
$this->termFieldName => [['target_id' => $this->term->id()]],
'langcode' => $this->baseLangcode,
]);
$node->save();
@ -91,14 +92,14 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
* Creates a test subject term, with translation.
*/
protected function setUpTerm() {
$this->term = $this->createTerm($this->vocabulary, array(
$this->term = $this->createTerm($this->vocabulary, [
'name' => $this->baseTagName,
'langcode' => $this->baseLangcode,
));
]);
$this->term->addTranslation($this->translateToLangcode, array(
$this->term->addTranslation($this->translateToLangcode, [
'name' => $this->translatedTagName,
));
]);
$this->term->save();
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Render\BubbleableMetadata;
@ -33,30 +33,30 @@ class TokenReplaceTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->fieldName = 'taxonomy_' . $this->vocabulary->id();
$handler_settings = array(
'target_bundles' => array(
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
),
],
'auto_create' => TRUE,
);
];
$this->createEntityReferenceField('node', 'article', $this->fieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
entity_get_form_display('node', 'article', 'default')
->setComponent($this->fieldName, array(
->setComponent($this->fieldName, [
'type' => 'options_select',
))
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->fieldName, array(
->setComponent($this->fieldName, [
'type' => 'entity_reference_label',
))
])
->save();
}
/**
* Creates some terms and a node, then tests the tokens generated from them.
*/
function testTaxonomyTokenReplacement() {
public function testTaxonomyTokenReplacement() {
$token_service = \Drupal::token();
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
@ -65,23 +65,23 @@ class TokenReplaceTest extends TaxonomyTestBase {
$term2 = $this->createTerm($this->vocabulary);
// Edit $term2, setting $term1 as parent.
$edit = array();
$edit = [];
$edit['name[0][value]'] = '<blink>Blinking Text</blink>';
$edit['parent[]'] = array($term1->id());
$edit['parent[]'] = [$term1->id()];
$this->drupalPostForm('taxonomy/term/' . $term2->id() . '/edit', $edit, t('Save'));
// Create node with term2.
$edit = array();
$node = $this->drupalCreateNode(array('type' => 'article'));
$edit = [];
$node = $this->drupalCreateNode(['type' => 'article']);
$edit[$this->fieldName . '[]'] = $term2->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
// Generate and test sanitized tokens for term1.
$tests = array();
$tests = [];
$tests['[term:tid]'] = $term1->id();
$tests['[term:name]'] = $term1->getName();
$tests['[term:description]'] = $term1->description->processed;
$tests['[term:url]'] = $term1->url('canonical', array('absolute' => TRUE));
$tests['[term:url]'] = $term1->url('canonical', ['absolute' => TRUE]);
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
@ -89,7 +89,7 @@ class TokenReplaceTest extends TaxonomyTestBase {
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
$metadata_tests = array();
$metadata_tests = [];
$metadata_tests['[term:tid]'] = $base_bubbleable_metadata;
$metadata_tests['[term:name]'] = $base_bubbleable_metadata;
$metadata_tests['[term:description]'] = $base_bubbleable_metadata;
@ -102,20 +102,20 @@ class TokenReplaceTest extends TaxonomyTestBase {
foreach ($tests as $input => $expected) {
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
$output = $token_service->replace($input, ['term' => $term1], ['langcode' => $language_interface->getId()], $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input]));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test sanitized tokens for term2.
$tests = array();
$tests = [];
$tests['[term:tid]'] = $term2->id();
$tests['[term:name]'] = $term2->getName();
$tests['[term:description]'] = $term2->description->processed;
$tests['[term:url]'] = $term2->url('canonical', array('absolute' => TRUE));
$tests['[term:url]'] = $term2->url('canonical', ['absolute' => TRUE]);
$tests['[term:node-count]'] = 1;
$tests['[term:parent:name]'] = $term1->getName();
$tests['[term:parent:url]'] = $term1->url('canonical', array('absolute' => TRUE));
$tests['[term:parent:url]'] = $term1->url('canonical', ['absolute' => TRUE]);
$tests['[term:parent:parent:name]'] = '[term:parent:parent:name]';
$tests['[term:vocabulary:name]'] = $this->vocabulary->label();
@ -123,12 +123,12 @@ class TokenReplaceTest extends TaxonomyTestBase {
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('term' => $term2), array('langcode' => $language_interface->getId()));
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
$output = $token_service->replace($input, ['term' => $term2], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', ['%token' => $input]));
}
// Generate and test sanitized tokens.
$tests = array();
$tests = [];
$tests['[vocabulary:vid]'] = $this->vocabulary->id();
$tests['[vocabulary:name]'] = $this->vocabulary->label();
$tests['[vocabulary:description]'] = $this->vocabulary->getDescription();
@ -139,8 +139,8 @@ class TokenReplaceTest extends TaxonomyTestBase {
$this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
foreach ($tests as $input => $expected) {
$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)));
$output = $token_service->replace($input, ['vocabulary' => $this->vocabulary], ['langcode' => $language_interface->getId()]);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy vocabulary token %token replaced.', ['%token' => $input]));
}
}

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
@ -19,12 +19,12 @@ class VocabularyCrudTest extends TaxonomyTestBase {
*
* @var array
*/
public static $modules = array('field_test', 'taxonomy_crud');
public static $modules = ['field_test', 'taxonomy_crud'];
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('create article content', 'administer taxonomy'));
$admin_user = $this->drupalCreateUser(['create article content', 'administer taxonomy']);
$this->drupalLogin($admin_user);
$this->vocabulary = $this->createVocabulary();
}
@ -32,7 +32,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
/**
* Test deleting a taxonomy that contains terms.
*/
function testTaxonomyVocabularyDeleteWithTerms() {
public function testTaxonomyVocabularyDeleteWithTerms() {
// Delete any existing vocabularies.
foreach (Vocabulary::loadMultiple() as $vocabulary) {
$vocabulary->delete();
@ -42,15 +42,15 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// Assert that there are no terms left.
$this->assertEqual(0, $query->execute(), 'There are no terms remaining.');
$terms = array();
$terms = [];
for ($i = 0; $i < 5; $i++) {
$terms[$i] = $this->createTerm($vocabulary);
}
// Set up hierarchy. term 2 is a child of 1 and 4 a child of 1 and 2.
$terms[2]->parent = array($terms[1]->id());
$terms[2]->parent = [$terms[1]->id()];
$terms[2]->save();
$terms[4]->parent = array($terms[1]->id(), $terms[2]->id());
$terms[4]->parent = [$terms[1]->id(), $terms[2]->id()];
$terms[4]->save();
// Assert that there are now 5 terms.
@ -65,7 +65,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
/**
* Ensure that the vocabulary static reset works correctly.
*/
function testTaxonomyVocabularyLoadStaticReset() {
public function testTaxonomyVocabularyLoadStaticReset() {
$original_vocabulary = Vocabulary::load($this->vocabulary->id());
$this->assertTrue(is_object($original_vocabulary), 'Vocabulary loaded successfully.');
$this->assertEqual($this->vocabulary->label(), $original_vocabulary->label(), 'Vocabulary loaded successfully.');
@ -89,7 +89,7 @@ class VocabularyCrudTest extends TaxonomyTestBase {
/**
* Tests for loading multiple vocabularies.
*/
function testTaxonomyVocabularyLoadMultiple() {
public function testTaxonomyVocabularyLoadMultiple() {
// Delete any existing vocabularies.
foreach (Vocabulary::loadMultiple() as $vocabulary) {
@ -119,45 +119,45 @@ class VocabularyCrudTest extends TaxonomyTestBase {
// Fetch the vocabularies with entity_load_multiple(), specifying IDs.
// Ensure they are returned in the same order as the original array.
$vocabularies = Vocabulary::loadMultiple(array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()));
$vocabularies = Vocabulary::loadMultiple([$vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()]);
$loaded_order = array_keys($vocabularies);
$expected_order = array($vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id());
$expected_order = [$vocabulary3->id(), $vocabulary2->id(), $vocabulary1->id()];
$this->assertIdentical($loaded_order, $expected_order);
// Test loading vocabularies by their properties.
$controller = $this->container->get('entity.manager')->getStorage('taxonomy_vocabulary');
// Fetch vocabulary 1 by name.
$vocabulary = current($controller->loadByProperties(array('name' => $vocabulary1->label())));
$vocabulary = current($controller->loadByProperties(['name' => $vocabulary1->label()]));
$this->assertEqual($vocabulary->id(), $vocabulary1->id(), 'Vocabulary loaded successfully by name.');
// Fetch vocabulary 2 by name and ID.
$vocabulary = current($controller->loadByProperties(array(
$vocabulary = current($controller->loadByProperties([
'name' => $vocabulary2->label(),
'vid' => $vocabulary2->id(),
)));
]));
$this->assertEqual($vocabulary->id(), $vocabulary2->id(), 'Vocabulary loaded successfully by name and ID.');
}
/**
* Test uninstall and reinstall of the taxonomy module.
*/
function testUninstallReinstall() {
public function testUninstallReinstall() {
// Field storages and fields attached to taxonomy term bundles should be
// removed when the module is uninstalled.
$field_name = Unicode::strtolower($this->randomMachineName() . '_field_name');
$storage_definition = array(
$storage_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'type' => 'text',
'cardinality' => 4
);
];
FieldStorageConfig::create($storage_definition)->save();
$field_definition = array(
$field_definition = [
'field_name' => $field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
'label' => $this->randomMachineName() . '_label',
);
];
FieldConfig::create($field_definition)->save();
// Remove the third party setting from the memory copy of the vocabulary.
@ -166,8 +166,8 @@ class VocabularyCrudTest extends TaxonomyTestBase {
$this->vocabulary->unsetThirdPartySetting('taxonomy_crud', 'foo');
require_once \Drupal::root() . '/core/includes/install.inc';
$this->container->get('module_installer')->uninstall(array('taxonomy'));
$this->container->get('module_installer')->install(array('taxonomy'));
$this->container->get('module_installer')->uninstall(['taxonomy']);
$this->container->get('module_installer')->install(['taxonomy']);
// Now create a vocabulary with the same name. All fields
// connected to this vocabulary name should have been removed when the

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\language\Entity\ConfigurableLanguage;
@ -13,7 +13,7 @@ use Drupal\language\Entity\ContentLanguageSettings;
*/
class VocabularyLanguageTest extends TaxonomyTestBase {
public static $modules = array('language');
public static $modules = ['language'];
protected function setUp() {
parent::setUp();
@ -22,21 +22,21 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
$this->drupalLogin($this->drupalCreateUser(['administer taxonomy']));
// Add some custom languages.
ConfigurableLanguage::create(array(
ConfigurableLanguage::create([
'id' => 'aa',
'label' => $this->randomMachineName(),
))->save();
])->save();
ConfigurableLanguage::create(array(
ConfigurableLanguage::create([
'id' => 'bb',
'label' => $this->randomMachineName(),
))->save();
])->save();
}
/**
* Tests language settings for vocabularies.
*/
function testVocabularyLanguage() {
public function testVocabularyLanguage() {
$this->drupalGet('admin/structure/taxonomy/add');
// Check that we have the language selector available.
@ -67,15 +67,15 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
/**
* Tests term language settings for vocabulary terms are saved and updated.
*/
function testVocabularyDefaultLanguageForTerms() {
public function testVocabularyDefaultLanguageForTerms() {
// Add a new vocabulary and check that the default language settings are for
// the terms are saved.
$edit = array(
$edit = [
'name' => $this->randomMachineName(),
'vid' => Unicode::strtolower($this->randomMachineName()),
'default_language[langcode]' => 'bb',
'default_language[language_alterable]' => TRUE,
);
];
$vid = $edit['vid'];
$this->drupalPostForm('admin/structure/taxonomy/add', $edit, t('Save'));
@ -93,10 +93,10 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
$this->assertFieldChecked('edit-default-language-language-alterable', 'Show language selection option is checked.');
// Edit the vocabulary and check that the new settings are updated.
$edit = array(
$edit = [
'default_language[langcode]' => 'aa',
'default_language[language_alterable]' => FALSE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
// And check again the settings and also the interface.
@ -109,11 +109,11 @@ class VocabularyLanguageTest extends TaxonomyTestBase {
$this->assertNoFieldChecked('edit-default-language-language-alterable', 'Show language selection option is not checked.');
// Check that language settings are changed after editing vocabulary.
$edit = array(
$edit = [
'name' => $this->randomMachineName(),
'default_language[langcode]' => 'authors_default',
'default_language[language_alterable]' => FALSE,
);
];
$this->drupalPostForm('admin/structure/taxonomy/manage/' . $vid, $edit, t('Save'));
// Check that we have the new settings.

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
/**
* Tests the taxonomy vocabulary permissions.
@ -18,12 +18,12 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
/**
* Create, edit and delete a taxonomy term via the user interface.
*/
function testVocabularyPermissionsTaxonomyTerm() {
public function testVocabularyPermissionsTaxonomyTerm() {
// Vocabulary used for creating, removing and editing terms.
$vocabulary = $this->createVocabulary();
// Test as admin user.
$user = $this->drupalCreateUser(array('administer taxonomy'));
$user = $this->drupalCreateUser(['administer taxonomy']);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
@ -32,14 +32,14 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
$this->assertField('edit-name-0-value', 'Add taxonomy term form opened successfully.');
// Submit the term.
$edit = array();
$edit = [];
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Created new term @name.', array('@name' => $edit['name[0][value]'])), 'Term created successfully.');
$this->assertText(t('Created new term @name.', ['@name' => $edit['name[0][value]']]), 'Term created successfully.');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
$terms = taxonomy_term_load_multiple_by_name($edit['name[0][value]']);
@ -52,18 +52,18 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Updated term @name.', array('@name' => $edit['name[0][value]'])), 'Term updated successfully.');
$this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', array('@entity-type' => 'taxonomy term', '%label' => $edit['name[0][value]'])), 'Delete taxonomy term form opened successfully.');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $edit['name[0][value]']]), 'Delete taxonomy term form opened successfully.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', array('%name' => $edit['name[0][value]'])), 'Term deleted.');
$this->assertRaw(t('Deleted term %name.', ['%name' => $edit['name[0][value]']]), 'Term deleted.');
// Test as user with "edit" permissions.
$user = $this->drupalCreateUser(array("edit terms in {$vocabulary->id()}"));
$user = $this->drupalCreateUser(["edit terms in {$vocabulary->id()}"]);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
@ -80,10 +80,10 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
$edit['name[0][value]'] = $this->randomMachineName();
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Updated term @name.', array('@name' => $edit['name[0][value]'])), 'Term updated successfully.');
$this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
// Verify that the update message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', array(':href' => 'term/'));
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Delete the vocabulary.
@ -91,7 +91,7 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
$this->assertResponse(403, 'Delete taxonomy term form open failed.');
// Test as user with "delete" permissions.
$user = $this->drupalCreateUser(array("delete terms in {$vocabulary->id()}"));
$user = $this->drupalCreateUser(["delete terms in {$vocabulary->id()}"]);
$this->drupalLogin($user);
// Visit the main taxonomy administration page.
@ -107,11 +107,11 @@ class VocabularyPermissionsTest extends TaxonomyTestBase {
// Delete the vocabulary.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', array('@entity-type' => 'taxonomy term', '%label' => $term->getName())), 'Delete taxonomy term form opened successfully.');
$this->assertRaw(t('Are you sure you want to delete the @entity-type %label?', ['@entity-type' => 'taxonomy term', '%label' => $term->getName()]), 'Delete taxonomy term form opened successfully.');
// Confirm deletion.
$this->drupalPostForm(NULL, NULL, t('Delete'));
$this->assertRaw(t('Deleted term %name.', array('%name' => $term->getName())), 'Term deleted.');
$this->assertRaw(t('Deleted term %name.', ['%name' => $term->getName()]), 'Term deleted.');
// Test as user without proper permissions.
$user = $this->drupalCreateUser();

View file

@ -1,6 +1,6 @@
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
@ -14,7 +14,7 @@ class VocabularyTranslationTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('content_translation', 'language');
public static $modules = ['content_translation', 'language'];
/**
* {@inheritdoc}
@ -32,7 +32,7 @@ class VocabularyTranslationTest extends TaxonomyTestBase {
/**
* Tests language settings for vocabularies.
*/
function testVocabularyLanguage() {
public function testVocabularyLanguage() {
$this->drupalGet('admin/structure/taxonomy/add');
// Check that the field to enable content translation is available.

View file

@ -2,7 +2,7 @@
namespace Drupal\Tests\taxonomy\Kernel\Migrate;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
@ -17,7 +17,7 @@ class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}

View file

@ -15,7 +15,7 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
@ -30,44 +30,44 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
* Tests the Drupal 6 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$expected_results = array(
'1' => array(
$expected_results = [
'1' => [
'source_vid' => 1,
'vid' => 'vocabulary_1_i_0_',
'weight' => 0,
'parent' => array(0),
),
'2' => array(
'parent' => [0],
],
'2' => [
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 3,
'parent' => array(0),
),
'3' => array(
'parent' => [0],
],
'3' => [
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 4,
'parent' => array(2),
),
'4' => array(
'parent' => [2],
],
'4' => [
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 6,
'parent' => array(0),
),
'5' => array(
'parent' => [0],
],
'5' => [
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 7,
'parent' => array(4),
),
'6' => array(
'parent' => [4],
],
'6' => [
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 8,
'parent' => array(4, 5),
),
);
'parent' => [4, 5],
],
];
$terms = Term::loadMultiple(array_keys($expected_results));
// Find each term in the tree.
@ -87,11 +87,11 @@ class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
$this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
$this->assertIdentical($values['vid'], $term->vid->target_id);
$this->assertIdentical((string) $values['weight'], $term->weight->value);
if ($values['parent'] === array(0)) {
if ($values['parent'] === [0]) {
$this->assertNull($term->parent->target_id);
}
else {
$parents = array();
$parents = [];
foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
$parents[] = (int) $parent->id();
}

View file

@ -15,7 +15,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
@ -32,7 +32,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
for ($i = 0; $i < 3; $i++) {
$j = $i + 1;
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
$this->assertIdentical($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
$this->assertIdentical($this->getMigration('d6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID([$j]), [$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());

View file

@ -34,7 +34,7 @@ class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
$this->assertIdentical('entity_reference_label', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
$this->assertIdentical(['node', 'article', 'default', 'tags'], $this->getMigration('d6_vocabulary_entity_display')->getIdMap()->lookupDestinationID([4, 'article']));
}
}

View file

@ -34,7 +34,7 @@ class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
$this->assertIdentical('options_select', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
$this->assertIdentical(['node', 'article', 'default', 'tags'], $this->getMigration('d6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID([4, 'article']));
// Test the term widget tags setting.
$entity_form_display = EntityFormDisplay::load('node.story.default');

View file

@ -48,7 +48,7 @@ class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
$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'), $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
$this->assertIdentical(['node', 'article', 'tags'], $this->getMigration('d6_vocabulary_field_instance')->getIdMap()->lookupDestinationID([4, 'article']));
// Test the the field vocabulary_1_i_0_
$field_id = 'node.story.vocabulary_1_i_0_';

View file

@ -39,7 +39,7 @@ class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
$this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
$this->assertIdentical(1, $field_storage->getCardinality(), "Field cardinality in 1.");
$this->assertIdentical(array('node', 'tags'), $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
$this->assertIdentical(['node', 'tags'], $this->getMigration('d6_vocabulary_field')->getIdMap()->lookupDestinationID([4]), "Test IdMap");
}
}

View file

@ -14,7 +14,7 @@ use Drupal\node\NodeInterface;
*/
class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
public static $modules = array(
public static $modules = [
'datetime',
'field',
'filter',
@ -24,7 +24,7 @@ class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
'taxonomy',
'telephone',
'text',
);
];
/**
* {@inheritdoc}
@ -40,21 +40,21 @@ class MigrateNodeTaxonomyTest extends MigrateDrupal7TestBase {
$this->executeMigration('d7_node_type');
FieldStorageConfig::create(array(
FieldStorageConfig::create([
'type' => 'entity_reference',
'field_name' => 'field_tags',
'entity_type' => 'node',
'settings' => array(
'settings' => [
'target_type' => 'taxonomy_term',
),
],
'cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED,
))->save();
])->save();
FieldConfig::create(array(
FieldConfig::create([
'entity_type' => 'node',
'field_name' => 'field_tags',
'bundle' => 'article',
))->save();
])->save();
$this->executeMigrations([
'd7_taxonomy_vocabulary',

View file

@ -16,7 +16,7 @@ class MigrateTaxonomyVocabularyTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}

View file

@ -18,14 +18,14 @@ class TermKernelTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array( 'filter', 'taxonomy', 'text', 'user' );
public static $modules = [ 'filter', 'taxonomy', 'text', 'user' ];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('filter'));
$this->installConfig(['filter']);
$this->installEntitySchema('taxonomy_term');
}
@ -38,11 +38,11 @@ class TermKernelTest extends KernelTestBase {
$valid_term = $this->createTerm($vocabulary);
// Delete a valid term.
$valid_term->delete();
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
$terms = entity_load_multiple_by_properties('taxonomy_term', ['vid' => $vocabulary->id()]);
$this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
// Delete an invalid term. Should not throw any notices.
entity_delete_multiple('taxonomy_term', array(42));
entity_delete_multiple('taxonomy_term', [42]);
}
/**
@ -53,18 +53,18 @@ class TermKernelTest extends KernelTestBase {
$parent_term1 = $this->createTerm($vocabulary);
$parent_term2 = $this->createTerm($vocabulary);
$child_term = $this->createTerm($vocabulary);
$child_term->parent = array($parent_term1->id(), $parent_term2->id());
$child_term->parent = [$parent_term1->id(), $parent_term2->id()];
$child_term->save();
$child_term_id = $child_term->id();
$parent_term1->delete();
$term_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
$term_storage->resetCache(array($child_term_id));
$term_storage->resetCache([$child_term_id]);
$child_term = Term::load($child_term_id);
$this->assertTrue(!empty($child_term), 'Child term is not deleted if only one of its parents is removed.');
$parent_term2->delete();
$term_storage->resetCache(array($child_term_id));
$term_storage->resetCache([$child_term_id]);
$child_term = Term::load($child_term_id);
$this->assertTrue(empty($child_term), 'Child term is deleted if all of its parents are removed.');
}
@ -75,7 +75,7 @@ class TermKernelTest extends KernelTestBase {
public function testTaxonomyVocabularyTree() {
// Create a new vocabulary with 6 terms.
$vocabulary = $this->createVocabulary();
$term = array();
$term = [];
for ($i = 0; $i < 6; $i++) {
$term[$i] = $this->createTerm($vocabulary);
}
@ -90,13 +90,13 @@ class TermKernelTest extends KernelTestBase {
$term[1]->save();
// $term[2] is a child of 1 and 5.
$term[2]->parent = array($term[1]->id(), $term[5]->id());
$term[2]->parent = [$term[1]->id(), $term[5]->id()];
$term[2]->save();
// $term[3] is a child of 2.
$term[3]->parent = array($term[2]->id());
$term[3]->parent = [$term[2]->id()];
$term[3]->save();
// $term[5] is a child of 4.
$term[5]->parent = array($term[4]->id());
$term[5]->parent = [$term[4]->id()];
$term[5]->save();
/**

View file

@ -16,7 +16,7 @@ class TermValidationTest extends EntityKernelTestBase {
*
* @var array
*/
public static $modules = array('taxonomy');
public static $modules = ['taxonomy'];
/**
* {@inheritdoc}
@ -30,14 +30,14 @@ class TermValidationTest extends EntityKernelTestBase {
* Tests the term validation constraints.
*/
public function testValidation() {
$this->entityManager->getStorage('taxonomy_vocabulary')->create(array(
$this->entityManager->getStorage('taxonomy_vocabulary')->create([
'vid' => 'tags',
'name' => 'Tags',
))->save();
$term = $this->entityManager->getStorage('taxonomy_term')->create(array(
])->save();
$term = $this->entityManager->getStorage('taxonomy_term')->create([
'name' => 'test',
'vid' => 'tags',
));
]);
$violations = $term->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default term.');
@ -46,7 +46,7 @@ class TermValidationTest extends EntityKernelTestBase {
$this->assertEqual(count($violations), 1, 'Violation found when name is too long.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name.0.value');
$field_label = $term->get('name')->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => $field_label, '@max' => 255)));
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', ['%name' => $field_label, '@max' => 255]));
$term->set('name', NULL);
$violations = $term->validate();
@ -58,7 +58,7 @@ class TermValidationTest extends EntityKernelTestBase {
$term->set('parent', 9999);
$violations = $term->validate();
$this->assertEqual(count($violations), 1, 'Violation found when term parent is invalid.');
$this->assertEqual($violations[0]->getMessage(), format_string('The referenced entity (%type: %id) does not exist.', array('%type' => 'taxonomy_term', '%id' => 9999)));
$this->assertEqual($violations[0]->getMessage(), format_string('The referenced entity (%type: %id) does not exist.', ['%type' => 'taxonomy_term', '%id' => 9999]));
$term->set('parent', 0);
$violations = $term->validate();

View file

@ -12,7 +12,7 @@ use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
class TaxonomyLocalTasksTest extends LocalTaskIntegrationTestBase {
protected function setUp() {
$this->directoryList = array('taxonomy' => 'core/modules/taxonomy');
$this->directoryList = ['taxonomy' => 'core/modules/taxonomy'];
parent::setUp();
}
@ -21,10 +21,10 @@ class TaxonomyLocalTasksTest extends LocalTaskIntegrationTestBase {
*
* @dataProvider getTaxonomyPageRoutes
*/
public function testTaxonomyPageLocalTasks($route, $subtask = array()) {
$tasks = array(
0 => array('entity.taxonomy_term.canonical', 'entity.taxonomy_term.edit_form'),
);
public function testTaxonomyPageLocalTasks($route, $subtask = []) {
$tasks = [
0 => ['entity.taxonomy_term.canonical', 'entity.taxonomy_term.edit_form'],
];
if ($subtask) $tasks[] = $subtask;
$this->assertLocalTasks($route, $tasks);
}
@ -33,10 +33,10 @@ class TaxonomyLocalTasksTest extends LocalTaskIntegrationTestBase {
* Provides a list of routes to test.
*/
public function getTaxonomyPageRoutes() {
return array(
array('entity.taxonomy_term.canonical'),
array('entity.taxonomy_term.edit_form'),
);
return [
['entity.taxonomy_term.canonical'],
['entity.taxonomy_term.edit_form'],
];
}
}