diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php.orig b/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php.orig deleted file mode 100644 index 44a4e83033..0000000000 --- a/core/modules/rest/tests/src/Functional/EntityResource/Term/TermResourceTestBase.php.orig +++ /dev/null @@ -1,181 +0,0 @@ -grantPermissionsToTestedRole(['access content']); - break; - case 'POST': - case 'PATCH': - case 'DELETE': - // Grant the 'create url aliases' permission to test the case when - // the path field is accessible, see - // \Drupal\Tests\rest\Functional\EntityResource\Node\NodeResourceTestBase - // for a negative test. - // @todo Update once https://www.drupal.org/node/2824408 lands. - $this->grantPermissionsToTestedRole(['administer taxonomy', 'create url aliases']); - break; - } - } - - /** - * {@inheritdoc} - */ - protected function createEntity() { - $vocabulary = Vocabulary::load('camelids'); - if (!$vocabulary) { - // Create a "Camelids" vocabulary. - $vocabulary = Vocabulary::create([ - 'name' => 'Camelids', - 'vid' => 'camelids', - ]); - $vocabulary->save(); - } - - // Create a "Llama" taxonomy term. - $term = Term::create(['vid' => $vocabulary->id()]) - ->setName('Llama') - ->setChangedTime(123456789) - ->set('path', '/llama'); - $term->save(); - - return $term; - } - - /** - * {@inheritdoc} - */ - protected function getExpectedNormalizedEntity() { - return [ - 'tid' => [ - ['value' => 1], - ], - 'uuid' => [ - ['value' => $this->entity->uuid()], - ], - 'vid' => [ - [ - 'target_id' => 'camelids', - 'target_type' => 'taxonomy_vocabulary', - 'target_uuid' => Vocabulary::load('camelids')->uuid(), - ], - ], - 'name' => [ - ['value' => 'Llama'], - ], - 'description' => [ - [ - 'value' => NULL, - 'format' => NULL, - ], - ], - 'parent' => [], - 'weight' => [ - ['value' => 0], - ], - 'langcode' => [ - [ - 'value' => 'en', - ], - ], - 'changed' => [ - $this->formatExpectedTimestampItemValues($this->entity->getChangedTime()), - ], - 'default_langcode' => [ - [ - 'value' => TRUE, - ], - ], - 'path' => [ - [ - 'alias' => '/llama', - 'pid' => 1, - 'langcode' => 'en', - ], - ], - ]; - } - - /** - * {@inheritdoc} - */ - protected function getNormalizedPostEntity() { - return [ - 'vid' => [ - [ - 'target_id' => 'camelids', - ], - ], - 'name' => [ - [ - 'value' => 'Dramallama', - ], - ], - 'description' => [ - [ - 'value' => 'Dramallamas are the coolest camelids.', - 'format' => NULL, - ], - ], - ]; - } - - /** - * {@inheritdoc} - */ - protected function getExpectedUnauthorizedAccessMessage($method) { - if ($this->config('rest.settings')->get('bc_entity_resource_permissions')) { - return parent::getExpectedUnauthorizedAccessMessage($method); - } - - switch ($method) { - case 'GET': - return "The 'access content' permission is required."; - case 'POST': - return "The 'administer taxonomy' permission is required."; - case 'PATCH': - return "The following permissions are required: 'edit terms in camelids' OR 'administer taxonomy'."; - case 'DELETE': - return "The following permissions are required: 'delete terms in camelids' OR 'administer taxonomy'."; - default: - return parent::getExpectedUnauthorizedAccessMessage($method); - } - } - -} diff --git a/core/modules/taxonomy/src/Entity/Term.php.orig b/core/modules/taxonomy/src/Entity/Term.php.orig deleted file mode 100644 index 03491ab962..0000000000 --- a/core/modules/taxonomy/src/Entity/Term.php.orig +++ /dev/null @@ -1,250 +0,0 @@ -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; - } - } - } - } - - // Delete term hierarchy information after looking up orphans but before - // deleting them so that their children/parent information is consistent. - $storage->deleteTermHierarchy(array_keys($entities)); - - if (!empty($orphans)) { - $storage->delete($orphans); - } - } - - /** - * {@inheritdoc} - */ - public function postSave(EntityStorageInterface $storage, $update = TRUE) { - parent::postSave($storage, $update); - - // Only change the parents if a value is set, keep the existing values if - // not. - if (isset($this->parent->target_id)) { - $storage->deleteTermHierarchy([$this->id()]); - $storage->updateTermHierarchy($this); - } - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - /** @var \Drupal\Core\Field\BaseFieldDefinition[] $fields */ - $fields = parent::baseFieldDefinitions($entity_type); - - $fields['tid']->setLabel(t('Term ID')) - ->setDescription(t('The term ID.')); - - $fields['uuid']->setDescription(t('The term UUID.')); - - $fields['vid']->setLabel(t('Vocabulary')) - ->setDescription(t('The vocabulary to which the term is assigned.')); - - $fields['langcode']->setDescription(t('The term language code.')); - - $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setTranslatable(TRUE) - ->setRequired(TRUE) - ->setSetting('max_length', 255) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'string', - 'weight' => -5, - ]) - ->setDisplayOptions('form', [ - 'type' => 'string_textfield', - 'weight' => -5, - ]) - ->setDisplayConfigurable('form', TRUE); - - $fields['description'] = BaseFieldDefinition::create('text_long') - ->setLabel(t('Description')) - ->setTranslatable(TRUE) - ->setDisplayOptions('view', [ - 'label' => 'hidden', - 'type' => 'text_default', - 'weight' => 0, - ]) - ->setDisplayConfigurable('view', TRUE) - ->setDisplayOptions('form', [ - 'type' => 'text_textfield', - 'weight' => 0, - ]) - ->setDisplayConfigurable('form', TRUE); - - $fields['weight'] = BaseFieldDefinition::create('integer') - ->setLabel(t('Weight')) - ->setDescription(t('The weight of this term in relation to other terms.')) - ->setDefaultValue(0); - - $fields['parent'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Term Parents')) - ->setDescription(t('The parents of this term.')) - ->setSetting('target_type', 'taxonomy_term') - ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) - ->setCustomStorage(TRUE); - - $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the term was last edited.')) - ->setTranslatable(TRUE); - - return $fields; - } - - /** - * {@inheritdoc} - */ - public function getDescription() { - return $this->get('description')->value; - } - - /** - * {@inheritdoc} - */ - public function setDescription($description) { - $this->set('description', $description); - return $this; - } - - /** - * {@inheritdoc} - */ - public function getFormat() { - return $this->get('description')->format; - } - - /** - * {@inheritdoc} - */ - public function setFormat($format) { - $this->get('description')->format = $format; - return $this; - } - - /** - * {@inheritdoc} - */ - public function getName() { - return $this->label(); - } - - /** - * {@inheritdoc} - */ - public function setName($name) { - $this->set('name', $name); - return $this; - } - - /** - * {@inheritdoc} - */ - public function getWeight() { - return $this->get('weight')->value; - } - - /** - * {@inheritdoc} - */ - public function setWeight($weight) { - $this->set('weight', $weight); - return $this; - } - - /** - * {@inheritdoc} - */ - public function getVocabularyId() { - @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.4.0 and will be removed before 9.0.0. Use ' . __CLASS__ . '::bundle() instead to get the vocabulary ID.', E_USER_DEPRECATED); - return $this->bundle(); - } - - /** - * {@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; - } - -} diff --git a/core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepth.php.orig b/core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepth.php.orig deleted file mode 100644 index 37abdd565e..0000000000 --- a/core/modules/taxonomy/src/Plugin/views/argument/IndexTidDepth.php.orig +++ /dev/null @@ -1,143 +0,0 @@ -termStorage = $termStorage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity.manager')->getStorage('taxonomy_term')); - } - - protected function defineOptions() { - $options = parent::defineOptions(); - - $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'] = [ - '#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'] = [ - '#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); - } - - /** - * Override defaultActions() to remove summary actions. - */ - protected function defaultActions($which = NULL) { - if ($which) { - if (in_array($which, ['ignore', 'not found', 'empty', 'default'])) { - return parent::defaultActions($which); - } - return; - } - $actions = parent::defaultActions(); - unset($actions['summary asc']); - unset($actions['summary desc']); - unset($actions['summary asc by count']); - unset($actions['summary desc by count']); - return $actions; - } - - public function query($group_by = FALSE) { - $this->ensureMyTable(); - - if (!empty($this->options['break_phrase'])) { - $break = static::breakString($this->argument); - if ($break->value === [-1]) { - return FALSE; - } - - $operator = (count($break->value) > 1) ? 'IN' : '='; - $tids = $break->value; - } - else { - $operator = "="; - $tids = $this->argument; - } - // Now build the subqueries. - $subquery = db_select('taxonomy_index', 'tn'); - $subquery->addField('tn', 'nid'); - $where = (new Condition('OR'))->condition('tn.tid', $tids, $operator); - $last = "tn"; - - if ($this->options['depth'] > 0) { - $subquery->leftJoin('taxonomy_term_hierarchy', 'th', "th.tid = tn.tid"); - $last = "th"; - foreach (range(1, abs($this->options['depth'])) as $count) { - $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.parent = th$count.tid"); - $where->condition("th$count.tid", $tids, $operator); - $last = "th$count"; - } - } - elseif ($this->options['depth'] < 0) { - foreach (range(1, abs($this->options['depth'])) as $count) { - $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.tid = th$count.parent"); - $where->condition("th$count.tid", $tids, $operator); - $last = "th$count"; - } - } - - $subquery->condition($where); - $this->query->addWhere(0, "$this->tableAlias.$this->realField", $subquery, 'IN'); - } - - public function title() { - $term = $this->termStorage->load($this->argument); - if (!empty($term)) { - return $term->getName(); - } - // TODO review text - return $this->t('No name'); - } - -} diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTidDepth.php.orig b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTidDepth.php.orig deleted file mode 100644 index 93115584c8..0000000000 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTidDepth.php.orig +++ /dev/null @@ -1,100 +0,0 @@ - $this->t('Is one of'), - ]; - } - - protected function defineOptions() { - $options = parent::defineOptions(); - - $options['depth'] = ['default' => 0]; - - return $options; - } - - public function buildExtraOptionsForm(&$form, FormStateInterface $form_state) { - parent::buildExtraOptionsForm($form, $form_state); - - $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() { - // If no filter values are present, then do nothing. - if (count($this->value) == 0) { - return; - } - elseif (count($this->value) == 1) { - // Sometimes $this->value is an array with a single element so convert it. - if (is_array($this->value)) { - $this->value = current($this->value); - } - $operator = '='; - } - else { - $operator = 'IN';# " IN (" . implode(', ', array_fill(0, sizeof($this->value), '%d')) . ")"; - } - - // The normal use of ensureMyTable() here breaks Views. - // So instead we trick the filter into using the alias of the base table. - // See https://www.drupal.org/node/271833. - // If a relationship is set, we must use the alias it provides. - if (!empty($this->relationship)) { - $this->tableAlias = $this->relationship; - } - // If no relationship, then use the alias of the base table. - else { - $this->tableAlias = $this->query->ensureTable($this->view->storage->get('base_table')); - } - - // Now build the subqueries. - $subquery = db_select('taxonomy_index', 'tn'); - $subquery->addField('tn', 'nid'); - $where = (new Condition('OR'))->condition('tn.tid', $this->value, $operator); - $last = "tn"; - - if ($this->options['depth'] > 0) { - $subquery->leftJoin('taxonomy_term_hierarchy', 'th', "th.tid = tn.tid"); - $last = "th"; - foreach (range(1, abs($this->options['depth'])) as $count) { - $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.parent = th$count.tid"); - $where->condition("th$count.tid", $this->value, $operator); - $last = "th$count"; - } - } - elseif ($this->options['depth'] < 0) { - foreach (range(1, abs($this->options['depth'])) as $count) { - $subquery->leftJoin('taxonomy_term_hierarchy', "th$count", "$last.tid = th$count.parent"); - $where->condition("th$count.tid", $this->value, $operator); - $last = "th$count"; - } - } - - $subquery->condition($where); - $this->query->addWhere($this->options['group'], "$this->tableAlias.$this->realField", $subquery, 'IN'); - } - -} diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 917056a05e..c52848a7ac 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -86,7 +86,7 @@ function taxonomy_update_8303() { foreach ($config_factory->listAll('views.view.') as $id) { $view = $config_factory->getEditable($id); $changed = FALSE; - foreach ($view->get('display') as $display_id => &$display) { + foreach (array_keys($view->get('display')) as $display_id) { $path = "display.$display_id.display_options.relationships.parent.table"; if (!empty($table = $view->get($path)) && $table == 'taxonomy_term_hierarchy') { $view->set($path, 'taxonomy_term__parent'); @@ -110,8 +110,6 @@ function taxonomy_update_8303() { } } - - /** * Drop the legacy table {taxonomy_term_hierarchy}. */ diff --git a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyUpdateTest.php b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyUpdateTest.php index 037b7f98d3..61e1084edb 100644 --- a/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyUpdateTest.php +++ b/core/modules/taxonomy/tests/src/Functional/Update/TaxonomyUpdateTest.php @@ -1,6 +1,6 @@ databaseDumpFiles = [ - __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', + __DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8-rc1.bare.standard.php.gz', ]; } @@ -90,7 +90,8 @@ protected function createTerms() { /** @var \Drupal\Component\Uuid\UuidInterface $uuid */ $uuid = \Drupal::service('uuid'); - $tids = [0]; // The root tid. + // The root tid. + $tids = [0]; for ($i = 0; $i < 4; $i++) { $name = $this->randomString(); $tid = $this->db->insert('taxonomy_term_data') @@ -130,7 +131,7 @@ protected function createTerms() { */ protected function createView() { $vid = Unicode::strtolower($this->randomMachineName()); - $file = __DIR__ . '/../../../tests/modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; + $file = __DIR__ . '/../../../modules/taxonomy_test_views/test_views/views.view.test_taxonomy_parent.yml'; $config = Yaml::decode(file_get_contents($file)); $this->db->insert('config') diff --git a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php.orig b/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php.orig deleted file mode 100644 index 6450e4d91e..0000000000 --- a/core/modules/taxonomy/tests/src/Kernel/Migrate/d6/MigrateTaxonomyTermTest.php.orig +++ /dev/null @@ -1,111 +0,0 @@ -installEntitySchema('taxonomy_term'); - $this->executeMigrations(['d6_taxonomy_vocabulary', 'd6_taxonomy_term']); - } - - /** - * Tests the Drupal 6 taxonomy term to Drupal 8 migration. - */ - public function testTaxonomyTerms() { - $expected_results = [ - '1' => [ - 'source_vid' => 1, - 'vid' => 'vocabulary_1_i_0_', - 'weight' => 0, - 'parent' => [0], - 'language' => 'zu', - ], - '2' => [ - 'source_vid' => 2, - 'vid' => 'vocabulary_2_i_1_', - 'weight' => 3, - 'parent' => [0], - 'language' => 'fr', - ], - '3' => [ - 'source_vid' => 2, - 'vid' => 'vocabulary_2_i_1_', - 'weight' => 4, - 'parent' => [2], - 'language' => 'fr', - ], - '4' => [ - 'source_vid' => 3, - 'vid' => 'vocabulary_3_i_2_', - 'weight' => 6, - 'parent' => [0], - ], - '5' => [ - 'source_vid' => 3, - 'vid' => 'vocabulary_3_i_2_', - 'weight' => 7, - 'parent' => [4], - ], - '6' => [ - 'source_vid' => 3, - 'vid' => 'vocabulary_3_i_2_', - 'weight' => 8, - 'parent' => [4, 5], - ], - ]; - $terms = Term::loadMultiple(array_keys($expected_results)); - - // Find each term in the tree. - $storage = \Drupal::entityTypeManager()->getStorage('taxonomy_term'); - $vids = array_unique(array_column($expected_results, 'vid')); - $tree_terms = []; - foreach ($vids as $vid) { - foreach ($storage->loadTree($vid) as $term) { - $tree_terms[$term->tid] = $term; - } - } - - foreach ($expected_results as $tid => $values) { - /** @var Term $term */ - $term = $terms[$tid]; - $language = isset($values['language']) ? $values['language'] . ' - ' : ''; - $this->assertSame("{$language}term {$tid} of vocabulary {$values['source_vid']}", $term->name->value); - $this->assertSame("{$language}description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value); - $this->assertSame($values['vid'], $term->vid->target_id); - $this->assertSame((string) $values['weight'], $term->weight->value); - if ($values['parent'] === [0]) { - $this->assertNull($term->parent->target_id); - } - else { - $parents = []; - foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) { - $parents[] = (int) $parent->id(); - } - $this->assertSame($parents, $values['parent']); - } - - $this->assertArrayHasKey($tid, $tree_terms, "Term $tid exists in vocabulary tree"); - $tree_term = $tree_terms[$tid]; - $this->assertEquals($values['parent'], $tree_term->parents, "Term $tid has correct parents in vocabulary tree"); - } - } - -}