diff --git a/core/modules/taxonomy/src/Plugin/Condition/Vocabulary.php b/core/modules/taxonomy/src/Plugin/Condition/VocabularyCondition.php similarity index 78% rename from core/modules/taxonomy/src/Plugin/Condition/Vocabulary.php rename to core/modules/taxonomy/src/Plugin/Condition/VocabularyCondition.php index cf09dcb..cbdcf97 100644 --- a/core/modules/taxonomy/src/Plugin/Condition/Vocabulary.php +++ b/core/modules/taxonomy/src/Plugin/Condition/VocabularyCondition.php @@ -19,31 +19,39 @@ * id = "vocabulary", * label = @Translation("Vocabulary"), * context = { - * "term" = { + * "taxonomy_term" = { * "type" = "entity:taxonomy_term" * } * } * ) */ -class Vocabulary extends ConditionPluginBase implements ContainerFactoryPluginInterface { +class VocabularyCondition extends ConditionPluginBase implements ContainerFactoryPluginInterface { /** - * The entity storage. + * The vocabulary storage. * * @var \Drupal\Core\Entity\EntityStorageInterface */ - protected $entityStorage; + protected $vocabularyStorage; /** * Creates a new NodeType instance. * * @param \Drupal\Core\Entity\EntityStorageInterface $entity_storage - * The entity manager. - * {@inheritdoc} + * The vocabulary storage. + * @param array $configuration + * The plugin configuration, i.e. an array with configuration values keyed + * by configuration option name. The special key 'context' may be used to + * initialize the defined contexts by setting it to an array of context + * values keyed by context names. + * @param string $plugin_id + * The plugin_id for the plugin instance. + * @param mixed $plugin_definition + * The plugin implementation definition. */ public function __construct(EntityStorageInterface $entity_storage, array $configuration, $plugin_id, $plugin_definition) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->entityStorage = $entity_storage; + $this->vocabularyStorage = $entity_storage; } /** @@ -65,7 +73,7 @@ public function buildConfigurationForm(array $form, array &$form_state) { $form = parent::buildConfigurationForm($form, $form_state); $options = array(); /* @var \Drupal\taxonomy\VocabularyInterface[] $vocabularies */ - $vocabularies = $this->entityStorage->loadMultiple(); + $vocabularies = $this->vocabularyStorage->loadMultiple(); foreach ($vocabularies as $vocabulary) { $options[$vocabulary->id()] = $vocabulary->label(); } @@ -92,8 +100,8 @@ public function defaultConfiguration() { * {@inheritdoc} */ public function submitConfigurationForm(array &$form, array &$form_state) { - $this->configuration['bundles'] = array_filter($form_state['values']['bundles']); parent::submitConfigurationForm($form, $form_state); + $this->configuration['bundles'] = array_filter($form_state['values']['bundles']); } /** @@ -121,7 +129,7 @@ public function evaluate() { return TRUE; } /* @var \Drupal\taxonomy\TermInterface $term */ - $term = $this->getContextValue('term'); + $term = $this->getContextValue('taxonomy_term'); return !empty($this->configuration['bundles'][$term->getVocabularyId()]); } diff --git a/core/modules/taxonomy/src/Tests/Plugin/Condition/VocabularyConditionTest.php b/core/modules/taxonomy/src/Tests/Plugin/Condition/VocabularyConditionTest.php index f127304..7606f2a 100644 --- a/core/modules/taxonomy/src/Tests/Plugin/Condition/VocabularyConditionTest.php +++ b/core/modules/taxonomy/src/Tests/Plugin/Condition/VocabularyConditionTest.php @@ -8,8 +8,11 @@ namespace Drupal\taxonomy\Tests\Plugin\Condition; use Drupal\Component\Utility\String; -use Drupal\Core\Language\Language; +use Drupal\Component\Utility\Unicode; +use Drupal\Core\Language\LanguageInterface; use Drupal\system\Tests\Entity\EntityUnitTestBase; +use Drupal\taxonomy\Entity\Term; +use Drupal\taxonomy\Entity\Vocabulary; use Drupal\taxonomy\VocabularyInterface; /** @@ -36,7 +39,6 @@ public static function getInfo() { public function setUp() { parent::setUp(); $this->installEntitySchema('taxonomy_term'); - $this->installConfig(array('taxonomy')); } /** @@ -55,10 +57,10 @@ public function testConditions() { $term2 = $this->createTerm($vocab2); // Assert term1 is in vocabulary1. - /* @var \Drupal\taxonomy\Plugin\Condition\Vocabulary $condition */ + /* @var \Drupal\taxonomy\Plugin\Condition\VocabularyCondition $condition */ $condition = $manager->createInstance('vocabulary') ->setConfig('bundles', array($vocab1->id() => $vocab1->label())) - ->setContextValue('term', $term1); + ->setContextValue('taxonomy_term', $term1); $this->assertTrue($condition->execute(), String::format('The term @term is in vocabulary @vocab', array( '@term' => $term1->label(), @@ -71,7 +73,7 @@ public function testConditions() { // Assert a term not in a vocabulary does not match. $condition = $manager->createInstance('vocabulary') ->setConfig('bundles', array($vocab1->id() => $vocab1->label())) - ->setContextValue('term', $term2); + ->setContextValue('taxonomy_term', $term2); $this->assertFalse($condition->execute(), String::format('The term @term is NOT in vocabulary @vocab', array( '@term' => $term1->label(), @@ -79,13 +81,13 @@ public function testConditions() { ))); // Assert term1 is in in either vocab1 or vocab2. - /* @var \Drupal\taxonomy\Plugin\Condition\Vocabulary $condition */ + /* @var \Drupal\taxonomy\Plugin\Condition\VocabularyCondition $condition */ $condition = $manager->createInstance('vocabulary') ->setConfig('bundles', array( $vocab1->id() => $vocab1->label(), $vocab2->id() => $vocab2->label(), )) - ->setContextValue('term', $term1); + ->setContextValue('taxonomy_term', $term1); $this->assertTrue($condition->execute(), String::format('The term @term is in vocabulary @vocab', array( '@term' => $term1->label(), @@ -105,12 +107,11 @@ public function testConditions() { */ protected function createVocabulary() { // Create a vocabulary. - $vocabulary = entity_create('taxonomy_vocabulary', array( + $vocabulary = Vocabulary::create(array( 'name' => $this->randomName(), 'description' => $this->randomName(), - 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, - 'weight' => mt_rand(0, 10), + 'vid' => Unicode::strtolower($this->randomName()), + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, )); $vocabulary->save(); return $vocabulary; @@ -120,10 +121,10 @@ protected function createVocabulary() { * Returns a new term with random properties in vocabulary $vid. */ protected function createTerm(VocabularyInterface $vocabulary) { - $term = entity_create('taxonomy_term', array( + $term = Term::create(array( 'name' => $this->randomName(), 'vid' => $vocabulary->id(), - 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, )); $term->save(); return $term;