diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 1fa80fc..672a0d1 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -251,7 +251,7 @@ public static function queue($name, $reliable = FALSE) { /** * Returns a key/value storage collection. * - * @param $collection + * @param string $collection * Name of the key/value collection to return. * * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface @@ -305,10 +305,10 @@ public static function entityQuery($entity_type, $conjunction = 'AND') { /** * Returns the entity query aggregate object for this entity type. * - * @param $entity_type + * @param string $entity_type * The entity type, e.g. node, for which the query object should be * returned. - * @param $conjunction + * @param string $conjunction * AND if all conditions in the query need to apply, OR if any of them is * enough. Optional, defaults to AND. * @@ -331,7 +331,7 @@ public static function flood() { /** * Returns the module handler. * - * @return \Drupal\Core\Extension\ModuleHandler + * @return \Drupal\Core\Extension\ModuleHandlerInterface */ public static function moduleHandler() { return static::$container->get('module_handler'); @@ -364,7 +364,7 @@ public static function token() { /** * Returns the url generator service. * - * @return \Drupal\Core\Routing\UrlGenerator + * @return \Drupal\Core\Routing\PathBasedGeneratorInterface * The url generator service. */ public static function urlGenerator() { @@ -374,7 +374,7 @@ public static function urlGenerator() { /** * Returns the string translation service. * - * @return \Drupal\Core\Translation\TranslationManager + * @return \Drupal\Core\StringTranslation\TranslationManager * The string translation manager. */ public static function translation() { diff --git a/core/lib/Drupal/Core/Controller/ControllerBase.php b/core/lib/Drupal/Core/Controller/ControllerBase.php new file mode 100644 index 0000000..2bfc4f2 --- /dev/null +++ b/core/lib/Drupal/Core/Controller/ControllerBase.php @@ -0,0 +1,264 @@ +container->get('plugin.manager.entity'); + } + + /** + * Returns the current primary database. + * + * @return \Drupal\Core\Database\Connection + * The current active database's master connection. + */ + protected function database() { + return $this->container->get('database'); + } + + /** + * Returns the requested cache bin. + * + * @param string $bin + * (optional) The cache bin for which the cache object should be returned, + * defaults to 'cache'. + * + * @return \Drupal\Core\Cache\CacheBackendInterface + * The cache object associated with the specified bin. + */ + protected function cache($bin = 'cache') { + return $this->container->get('cache.' . $bin); + } + + /** + * Returns an expirable key value store collection. + * + * @param string $collection + * The name of the collection holding key and value pairs. + * + * @return \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface + * An expirable key value store collection. + */ + protected function keyValueExpirable($collection) { + return $this->container->get('keyvalue.expirable')->get($collection); + } + + /** + * Returns the locking layer instance. + * + * @return \Drupal\Core\Lock\LockBackendInterface + */ + protected function lock() { + return $this->container->get('lock'); + } + + /** + * Retrieves a configuration object. + * + * This is the main entry point to the configuration API. Calling + * @code Drupal::config('book.admin') @endcode will return a configuration + * object in which the book module can store its administrative settings. + * + * @param string $name + * The name of the configuration object to retrieve. The name corresponds to + * a configuration file. For @code config('book.admin') @endcode, the config + * object returned will contain the contents of book.admin configuration file. + * + * @return \Drupal\Core\Config\Config + * A configuration object. + */ + protected function config($name) { + return $this->container->get('config.factory')->get($name); + } + + /** + * Returns a queue for the given queue name. + * + * The following variables can be set by variable_set or $conf overrides: + * - queue_class_$name: The class to be used for the queue $name. + * - queue_default_class: The class to use when queue_class_$name is not + * defined. Defaults to \Drupal\Core\Queue\System, a reliable backend using + * SQL. + * - queue_default_reliable_class: The class to use when queue_class_$name is + * not defined and the queue_default_class is not reliable. Defaults to + * \Drupal\Core\Queue\System. + * + * @param string $name + * The name of the queue to work with. + * @param bool $reliable + * (optional) TRUE if the ordering of items and guaranteeing every item + * executes at least once is important, FALSE if scalability is the main + * concern. Defaults to FALSE. + * + * @return \Drupal\Core\Queue\QueueInterface + * The queue object for a given name. + */ + protected function queue($name, $reliable = FALSE) { + return $this->container->get('queue')->get($name, $reliable); + } + + /** + * Returns a key/value storage collection. + * + * @param string $collection + * Name of the key/value collection to return. + * + * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + protected function keyValue($collection) { + return $this->container->get('keyvalue')->get($collection); + } + + /** + * Returns the state storage service. + * + * Use this to store machine-generated data, local to a specific environment + * that does not need deploying and does not need human editing; for example, + * the last time cron was run. Data which needs to be edited by humans and + * needs to be the same across development, production, etc. environments + * (for example, the system maintenance message) should use config() instead. + * + * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + protected function state() { + return $this->container->get('state'); + } + + /** + * Returns the default http client. + * + * @return \Guzzle\Http\ClientInterface + * A guzzle http client instance. + */ + protected function httpClient() { + return $this->container->get('http_default_client'); + } + + /** + * Returns the entity query object for this entity type. + * + * @param string $entity_type + * The entity type, e.g. node, for which the query object should be + * returned. + * @param string $conjunction + * AND if all conditions in the query need to apply, OR if any of them is + * enough. Optional, defaults to AND. + * + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query object that can query the given entity type. + */ + protected function entityQuery($entity_type, $conjunction = 'AND') { + return $this->container->get('entity.query')->get($entity_type, $conjunction); + } + + /** + * Returns the entity query aggregate object for this entity type. + * + * @param string $entity_type + * The entity type, e.g. node, for which the query object should be + * returned. + * @param string $conjunction + * AND if all conditions in the query need to apply, OR if any of them is + * enough. Optional, defaults to AND. + * + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query object that can query the given entity type. + */ + protected function entityQueryAggregate($entity_type, $conjunction = 'AND') { + return $this->container->get('entity.query')->getAggregate($entity_type, $conjunction); + } + + /** + * Returns the flood instance. + * + * @return \Drupal\Core\Flood\FloodInterface + */ + protected function flood() { + return $this->container->get('flood'); + } + + /** + * Returns the module handler. + * + * @return \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected function moduleHandler() { + return $this->container->get('module_handler'); + } + + /** + * Returns the typed data manager service. + * + * Use the typed data manager service for creating typed data objects. + * + * @return \Drupal\Core\TypedData\TypedDataManager + * The typed data manager. + * + * @see \Drupal\Core\TypedData\TypedDataManager::create() + */ + protected function typedData() { + return $this->container->get('typed_data'); + } + + /** + * Returns the token service. + * + * @return \Drupal\Core\Utility\Token + * The token service. + */ + protected function token() { + return $this->container->get('token'); + } + + /** + * Returns the url generator service. + * + * @return \Drupal\Core\Routing\PathBasedGeneratorInterface + * The url generator service. + */ + protected function urlGenerator() { + return $this->container->get('url_generator'); + } + + /** + * Returns the string translation service. + * + * @return \Drupal\Core\StringTranslation\TranslationManager + * The string translation manager. + */ + protected function translation() { + return $this->container->get('string_translation'); + } + + /** + * Returns the language manager service. + * + * @return \Drupal\Core\Language\LanguageManager + * The language manager. + */ + protected function languageManager() { + return $this->container->get('language_manager'); + } + +} diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php index 74c3d12..938cc7b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php @@ -7,66 +7,14 @@ namespace Drupal\taxonomy\Controller; -use Drupal\Core\Controller\ControllerInterface; -use Drupal\Core\Entity\EntityManager; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\taxonomy\TermStorageControllerInterface; +use Drupal\Core\Controller\ControllerBase; use Drupal\taxonomy\VocabularyInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides route responses for taxonomy.module. */ -class TaxonomyController implements ControllerInterface { - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManager - */ - protected $entityManager; - - /** - * The taxonomy term storage. - * - * @var \Drupal\taxonomy\TermStorageControllerInterface - */ - protected $termStorage; - - /** - * Constructs a new TaxonomyController. - * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. - * @param \Drupal\Core\Entity\EntityManager $entity_manager - * The entity manager. - * @param \Drupal\taxonomy\TermStorageControllerInterface $term_storage - * The taxonomy term storage. - */ - public function __construct(ModuleHandlerInterface $module_handler, EntityManager $entity_manager, TermStorageControllerInterface $term_storage) { - $this->moduleHandler = $module_handler; - $this->entityManager = $entity_manager; - $this->termStorage = $term_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - $entity_manager = $container->get('plugin.manager.entity'); - return new static( - $container->get('module_handler'), - $entity_manager, - $entity_manager->getStorageController('taxonomy_term') - ); - } +class TaxonomyController extends ControllerBase { /** * Returns a rendered edit form to create a new term associated to the given vocabulary. @@ -78,11 +26,11 @@ public static function create(ContainerInterface $container) { * The taxonomy term add form. */ public function addForm(VocabularyInterface $taxonomy_vocabulary) { - $term = $this->termStorage->create(array('vid' => $taxonomy_vocabulary->id())); - if ($this->moduleHandler->moduleExists('language')) { + $term = $this->entityManager()->getStorageController('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id())); + if ($this->moduleHandler()->moduleExists('language')) { $term->langcode = language_get_default_langcode('taxonomy_term', $taxonomy_vocabulary->id()); } - return $this->entityManager->getForm($term); + return $this->entityManager()->getForm($term); } }