Commit 2825cc0c authored by webchick's avatar webchick

Issue #1763974 follow-up by neclimdul, sun: Put in temporary entity info hook...

Issue #1763974 follow-up by neclimdul, sun: Put in temporary entity info hook shiv until conversions are complete.
parent 536a61b8
......@@ -11,22 +11,43 @@
*/
/**
* Alter the entity type definition.
* Add to entity type definitions.
*
* Modules may implement this hook to add information to defined entity types.
*
* @param array $entity_info
* An associative array of all entity type definitions, keyed by the entity
* type name. Passed by reference.
*
* @see \Drupal\Core\Entity\Entity
* @see \Drupal\Core\Entity\EntityManager
* @see entity_get_info()
*/
function hook_entity_info(&$entity_info) {
// Add the 'Print' view mode for nodes.
$entity_info['node']['view_modes']['print'] = array(
'label' => t('Print'),
'custom_settings' => FALSE,
);
}
/**
* Alter the entity type definitions.
*
* Modules may implement this hook to alter the information that defines an
* entity. All properties that are available in
* entity type. All properties that are available in
* \Drupal\Core\Entity\EntityManager can be altered here.
*
* Do not use this hook to add information to entity types. Use
* hook_entity_info() for that instead.
*
* @param array $entity_info
* An associative array of all entity type definitions, keyed by the entity
* type name.
* type name. Passed by reference.
*
* @see \Drupal\Core\Entity\Entity
* @see \Drupal\Core\Entity\EntityManager
* @see entity_get_info()
*
* @todo Allow a module to add its bundles and view modes before other modules
* alter the definition.
*/
function hook_entity_info_alter(&$entity_info) {
// Set the controller class for nodes to an alternate implementation of the
......
......@@ -11,6 +11,7 @@
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
use Drupal\Core\Plugin\Discovery\InfoHookDecorator;
use Drupal\Core\Cache\CacheBackendInterface;
/**
......@@ -222,7 +223,7 @@ class EntityManager extends PluginManagerBase {
*/
public function __construct() {
// Allow the plugin definition to be altered by hook_entity_info_alter().
$this->discovery = new AlterDecorator(new AnnotatedClassDiscovery('Core', 'Entity'), 'entity_info');
$this->discovery = new AlterDecorator(new InfoHookDecorator(new AnnotatedClassDiscovery('Core', 'Entity'), 'entity_info'), 'entity_info');
$this->factory = new DefaultFactory($this);
// Entity type plugins includes translated strings, so each language is
......
......@@ -35,7 +35,7 @@ class AlterDecorator implements DiscoveryInterface {
* @param Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
* The object implementing DiscoveryInterface that is being decorated.
* @param string $hook
* The name of the alter hook that will be implemented by this discovery instance.
* The name of the alter hook that will be used by this discovery instance.
*/
public function __construct(DiscoveryInterface $decorated, $hook) {
$this->decorated = $decorated;
......
<?php
/**
* @file
* Contains Drupal\Core\Plugin\Discovery\InfoHookDecorator.
*/
namespace Drupal\Core\Plugin\Discovery;
use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
/**
* Allows info hook implementations to enhance discovered plugin definitions.
*/
class InfoHookDecorator implements DiscoveryInterface {
/**
* The Discovery object being decorated.
*
* @var Drupal\Component\Plugin\Discovery\DiscoveryInterface
*/
protected $decorated;
/**
* The name of the info hook that will be implemented by this discovery instance.
*
* @var string
*/
protected $hook;
/**
* Constructs a InfoHookDecorator object.
*
* @param Drupal\Component\Plugin\Discovery\DiscoveryInterface $decorated
* The object implementing DiscoveryInterface that is being decorated.
* @param string $hook
* The name of the info hook to be invoked by this discovery instance.
*/
public function __construct(DiscoveryInterface $decorated, $hook) {
$this->decorated = $decorated;
$this->hook = $hook;
}
/**
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition().
*/
public function getDefinition($plugin_id) {
$definitions = $this->getDefinitions();
return isset($definitions[$plugin_id]) ? $definitions[$plugin_id] : NULL;
}
/**
* Implements Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinitions().
*/
public function getDefinitions() {
$definitions = $this->decorated->getDefinitions();
foreach (module_implements($this->hook) as $module) {
$function = $module . '_' . $this->hook;
$function($definitions);
}
return $definitions;
}
/**
* Passes through all unknown calls onto the decorated object.
*/
public function __call($method, $args) {
return call_user_func_array(array($this->decorated, $method), $args);
}
}
......@@ -246,9 +246,9 @@ function book_admin_paths() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_info().
*/
function book_entity_info_alter(&$info) {
function book_entity_info(&$info) {
// Add the 'Print' view mode for nodes.
$info['node']['view_modes']['print'] = array(
'label' => t('Print'),
......
......@@ -98,9 +98,9 @@ function comment_help($path, $arg) {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_info().
*/
function comment_entity_info_alter(&$info) {
function comment_entity_info(&$info) {
foreach (node_type_get_names() as $type => $name) {
$info['comment']['bundles']['comment_node_' . $type] = array(
'label' => t('@node_type comment', array('@node_type' => $name)),
......
......@@ -192,9 +192,9 @@ function node_cron() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_info().
*/
function node_entity_info_alter(&$info) {
function node_entity_info(&$info) {
// Add a translation handler for fields if the language module is enabled.
if (module_exists('language')) {
$info['node']['translation']['node'] = TRUE;
......
......@@ -106,9 +106,9 @@ function taxonomy_permission() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_info().
*/
function taxonomy_entity_info_alter(&$info) {
function taxonomy_entity_info(&$info) {
foreach (taxonomy_vocabulary_get_names() as $machine_name => $vocabulary) {
$info['taxonomy_term']['bundles'][$machine_name] = array(
'label' => $vocabulary->name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment