Commit 2fa3ffe1 authored by Dries's avatar Dries

Issue #1822458 by tim.plunkett, effulgentsia: Move dynamic parts (view modes,...

Issue #1822458 by tim.plunkett, effulgentsia: Move dynamic parts (view modes, bundles) out of entity_info().
parent de63cbb8
...@@ -24,11 +24,114 @@ ...@@ -24,11 +24,114 @@
* @see entity_get_info() * @see entity_get_info()
*/ */
function hook_entity_info(&$entity_info) { function hook_entity_info(&$entity_info) {
// Add the 'Print' view mode for nodes. // Add a form controller for a custom node form without overriding the default
$entity_info['node']['view_modes']['print'] = array( // node form. To override the default node form, use hook_entity_info_alter()
'label' => t('Print'), // to alter $entity_info['node']['form_controller_class']['default'].
'custom_settings' => FALSE, $entity_info['node']['form_controller_class']['mymodule_foo'] = 'Drupal\mymodule\NodeFooFormController';
}
/**
* Describe the view modes for entity types.
*
* View modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page ('full'
* mode), on the home page or taxonomy listings ('teaser' mode), or in an RSS
* feed ('rss' mode). Modules taking part in the display of the entity (notably
* the Field API) can adjust their behavior depending on the requested view
* mode. An additional 'default' view mode is available for all entity types.
* This view mode is not intended for actual entity display, but holds default
* display settings. For each available view mode, administrators can configure
* whether it should use its own set of field display settings, or just
* replicate the settings of the 'default' view mode, thus reducing the amount
* of display configurations to keep track of.
*
* @return array
* An associative array of all entity view modes, keyed by the entity
* type name, and then the view mode name, with the following keys:
* - label: The human-readable name of the view mode.
* - custom_settings: A boolean specifying whether the view mode should by
* default use its own custom field display settings. If FALSE, entities
* displayed in this view mode will reuse the 'default' display settings
* by default (e.g. right after the module exposing the view mode is
* enabled), but administrators can later use the Field UI to apply custom
* display settings specific to the view mode.
*
* @see entity_get_view_modes()
* @see hook_entity_view_mode_info_alter()
*/
function hook_entity_view_mode_info() {
$view_modes['user']['full'] = array(
'label' => t('User account'),
);
$view_modes['user']['compact'] = array(
'label' => t('Compact'),
'custom_settings' => TRUE,
);
return $view_modes;
}
/**
* Alter the view modes for entity types.
*
* @param array $view_modes
* An array of view modes, keyed first by entity type, then by view mode name.
*
* @see entity_get_view_modes()
* @see hook_entity_view_mode_info()
*/
function hook_entity_view_mode_info_alter(&$view_modes) {
$view_modes['user']['full']['custom_settings'] = TRUE;
}
/**
* Describe the bundles for entity types.
*
* @return array
* An associative array of all entity bundles, keyed by the entity
* type name, and then the bundle name, with the following keys:
* - label: The human-readable name of the bundle.
* - uri_callback: The same as the 'uri_callback' key defined for the entity
* type in the EntityManager, but for the bundle only. When determining
* the URI of an entity, if a 'uri_callback' is defined for both the
* entity type and the bundle, the one for the bundle is used.
* - admin: An array of information that allows Field UI pages to attach
* themselves to the existing administration pages for the bundle.
* Elements:
* - path: the path of the bundle's main administration page, as defined
* in hook_menu(). If the path includes a placeholder for the bundle,
* the 'bundle argument', 'bundle helper' and 'real path' keys below
* are required.
* - bundle argument: The position of the placeholder in 'path', if any.
* - real path: The actual path (no placeholder) of the bundle's main
* administration page. This will be used to generate links.
* - access callback: As in hook_menu(). 'user_access' will be assumed if
* no value is provided.
* - access arguments: As in hook_menu().
*
* @see entity_get_bundles()
* @see hook_entity_bundle_info_alter()
*/
function hook_entity_bundle_info() {
$bundles['user']['user'] = array(
'label' => t('User'),
'admin' => array(
'path' => 'admin/config/people/accounts',
),
); );
return $bundles;
}
/**
* Alter the bundles for entity types.
*
* @param array $bundles
* An array of bundles, keyed first by entity type, then by bundle name.
*
* @see entity_get_bundles()
* @see hook_entity_bundle_info()
*/
function hook_entity_bundle_info_alter(&$bundles) {
$bundles['user']['user']['label'] = t('Full account');
} }
/** /**
......
...@@ -49,23 +49,91 @@ function entity_get_info($entity_type = NULL) { ...@@ -49,23 +49,91 @@ function entity_get_info($entity_type = NULL) {
*/ */
function entity_info_cache_clear() { function entity_info_cache_clear() {
drupal_static_reset('entity_get_info'); drupal_static_reset('entity_get_info');
drupal_static_reset('entity_get_view_modes');
drupal_static_reset('entity_get_bundles');
// Clear all languages. // Clear all languages.
cache()->deleteTags(array('entity_info' => TRUE)); cache()->deleteTags(array('entity_info' => TRUE));
} }
/** /**
* Returns the defined bundles for the given entity type. * Returns the entity bundle info.
* *
* @param string $entity_type * @param string|null $entity_type
* The entity type whose bundles should be returned. * The entity type whose bundle info should be returned, or NULL for all
* bundles info. Defaults to NULL.
* *
* @return array * @return array
* An array containing the bundle names or the entity type name itself if no * The bundle info for a specific entity type, or all entity types.
* bundle is defined.
*/ */
function entity_get_bundles($entity_type) { function entity_get_bundles($entity_type = NULL) {
$entity_info = entity_get_info($entity_type); $bundles = &drupal_static(__FUNCTION__);
return isset($entity_info['bundles']) ? array_keys($entity_info['bundles']) : array($entity_type); if (!$bundles) {
$langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode;
if ($cache = cache()->get("entity_bundle_info:$langcode")) {
$bundles = $cache->data;
}
else {
$bundles = module_invoke_all('entity_bundle_info');
// If no bundles are provided, use the entity type name and label.
foreach (entity_get_info() as $type => $entity_info) {
if (!isset($bundles[$type])) {
$bundles[$type][$type]['label'] = $entity_info['label'];
}
}
drupal_alter('entity_bundle_info', $bundles);
cache()->set("entity_bundle_info:$langcode", $bundles, CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE));
}
}
if (empty($entity_type)) {
return $bundles;
}
elseif (isset($bundles[$entity_type])) {
return $bundles[$entity_type];
}
return array();
}
/**
* Returns the entity view mode info.
*
* @param string|null $entity_type
* The entity type whose view mode info should be returned, or NULL for all
* view mode info. Defaults to NULL.
*
* @return array
* The view mode info for a specific entity type, or all entity types.
*/
function entity_get_view_modes($entity_type = NULL) {
$view_modes = &drupal_static(__FUNCTION__);
if (!$view_modes) {
$langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode;
if ($cache = cache()->get("entity_view_mode_info:$langcode")) {
$view_modes = $cache->data;
}
else {
$view_modes = module_invoke_all('entity_view_mode_info');
foreach ($view_modes as $type => $entity_info) {
foreach ($entity_info as $view_mode => $view_mode_info) {
$view_modes[$type][$view_mode] += array(
'custom_settings' => FALSE,
);
}
}
drupal_alter('entity_view_mode_info', $view_modes);
cache()->set("entity_view_mode_info:$langcode", $view_modes, CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE));
}
}
if (empty($entity_type)) {
return $view_modes;
}
elseif (isset($view_modes[$entity_type])) {
return $view_modes[$entity_type];
}
return array();
} }
/** /**
......
...@@ -154,8 +154,9 @@ public function uri() { ...@@ -154,8 +154,9 @@ public function uri() {
// A bundle-specific callback takes precedence over the generic one for the // A bundle-specific callback takes precedence over the generic one for the
// entity type. // entity type.
$entity_info = $this->entityInfo(); $entity_info = $this->entityInfo();
if (isset($entity_info['bundles'][$bundle]['uri_callback'])) { $bundles = entity_get_bundles($this->entityType);
$uri_callback = $entity_info['bundles'][$bundle]['uri_callback']; if (isset($bundles[$bundle]['uri_callback'])) {
$uri_callback = $bundles[$bundle]['uri_callback'];
} }
elseif (isset($entity_info['uri_callback'])) { elseif (isset($entity_info['uri_callback'])) {
$uri_callback = $entity_info['uri_callback']; $uri_callback = $entity_info['uri_callback'];
......
...@@ -109,49 +109,6 @@ ...@@ -109,49 +109,6 @@
* Elements: * Elements:
* - bundle: The name of the property that contains the name of the bundle * - bundle: The name of the property that contains the name of the bundle
* object. * object.
* - bundles: An array describing all bundles for this object type. Keys are
* bundle machine names, as found in the objects' 'bundle' property
* (defined in the 'entity_keys' entry for the entity type in the
* EntityManager). Elements:
* - label: The human-readable name of the bundle.
* - uri_callback: The same as the 'uri_callback' key defined for the entity
* type in the EntityManager, but for the bundle only. When determining
* the URI of an entity, if a 'uri_callback' is defined for both the
* entity type and the bundle, the one for the bundle is used.
* - admin: An array of information that allows Field UI pages to attach
* themselves to the existing administration pages for the bundle.
* Elements:
* - path: the path of the bundle's main administration page, as defined
* in hook_menu(). If the path includes a placeholder for the bundle,
* the 'bundle argument', 'bundle helper' and 'real path' keys below
* are required.
* - bundle argument: The position of the placeholder in 'path', if any.
* - real path: The actual path (no placeholder) of the bundle's main
* administration page. This will be used to generate links.
* - access callback: As in hook_menu(). 'user_access' will be assumed if
* no value is provided.
* - access arguments: As in hook_menu().
* - view_modes: An array describing the view modes for the entity type. View
* modes let entities be displayed differently depending on the context.
* For instance, a node can be displayed differently on its own page
* ('full' mode), on the home page or taxonomy listings ('teaser' mode), or
* in an RSS feed ('rss' mode). Modules taking part in the display of the
* entity (notably the Field API) can adjust their behavior depending on
* the requested view mode. An additional 'default' view mode is available
* for all entity types. This view mode is not intended for actual entity
* display, but holds default display settings. For each available view
* mode, administrators can configure whether it should use its own set of
* field display settings, or just replicate the settings of the 'default'
* view mode, thus reducing the amount of display configurations to keep
* track of. Keys of the array are view mode names. Each view mode is
* described by an array with the following key/value pairs:
* - label: The human-readable name of the view mode.
* - custom_settings: A boolean specifying whether the view mode should by
* default use its own custom field display settings. If FALSE, entities
* displayed in this view mode will reuse the 'default' display settings
* by default (e.g. right after the module exposing the view mode is
* enabled), but administrators can later use the Field UI to apply custom
* display settings specific to the view mode.
* - menu_base_path: (optional) The base menu router path to which the entity * - menu_base_path: (optional) The base menu router path to which the entity
* administration user interface responds. It can be used to generate UI * administration user interface responds. It can be used to generate UI
* links and to attach additional router items to the entity UI in a generic * links and to attach additional router items to the entity UI in a generic
...@@ -229,8 +186,6 @@ class EntityManager extends PluginManagerBase { ...@@ -229,8 +186,6 @@ class EntityManager extends PluginManagerBase {
'access_controller_class' => 'Drupal\Core\Entity\EntityAccessController', 'access_controller_class' => 'Drupal\Core\Entity\EntityAccessController',
'static_cache' => TRUE, 'static_cache' => TRUE,
'translation' => array(), 'translation' => array(),
'bundles' => array(),
'view_modes' => array(),
); );
/** /**
...@@ -286,17 +241,6 @@ public function processDefinition(&$definition, $plugin_id) { ...@@ -286,17 +241,6 @@ public function processDefinition(&$definition, $plugin_id) {
return; return;
} }
foreach ($definition['view_modes'] as $view_mode => $view_mode_info) {
$definition['view_modes'][$view_mode] += array(
'custom_settings' => FALSE,
);
}
// If no bundle key is provided, assume a single bundle, named after
// the entity type.
if (empty($definition['entity_keys']['bundle']) && empty($definition['bundles'])) {
$definition['bundles'] = array($plugin_id => array('label' => $definition['label']));
}
// Prepare entity schema fields SQL info for // Prepare entity schema fields SQL info for
// Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery(). // Drupal\Core\Entity\DatabaseStorageControllerInterface::buildQuery().
if (isset($definition['base_table'])) { if (isset($definition['base_table'])) {
......
...@@ -250,14 +250,14 @@ function book_admin_paths() { ...@@ -250,14 +250,14 @@ function book_admin_paths() {
} }
/** /**
* Implements hook_entity_info(). * Implements hook_entity_view_mode_info().
*/ */
function book_entity_info(&$info) { function book_entity_view_mode_info() {
// Add the 'Print' view mode for nodes. // Add the 'Print' view mode for nodes.
$info['node']['view_modes']['print'] = array( $view_modes['node']['print'] = array(
'label' => t('Print'), 'label' => t('Print'),
'custom_settings' => FALSE,
); );
return $view_modes;
} }
/** /**
......
...@@ -99,11 +99,22 @@ function comment_help($path, $arg) { ...@@ -99,11 +99,22 @@ function comment_help($path, $arg) {
} }
/** /**
* Implements hook_entity_info(). * Implements hook_entity_view_mode_info().
*/ */
function comment_entity_info(&$info) { function comment_entity_view_mode_info() {
$view_modes['comment']['full'] = array(
'label' => t('Full comment'),
);
return $view_modes;
}
/**
* Implements hook_entity_bundle_info().
*/
function comment_entity_bundle_info() {
$bundles = array();
foreach (node_type_get_names() as $type => $name) { foreach (node_type_get_names() as $type => $name) {
$info['comment']['bundles']['comment_node_' . $type] = array( $bundles['comment']['comment_node_' . $type] = array(
'label' => t('@node_type comment', array('@node_type' => $name)), 'label' => t('@node_type comment', array('@node_type' => $name)),
// Provide the node type/bundle name for other modules, so it does not // Provide the node type/bundle name for other modules, so it does not
// have to be extracted manually from the bundle name. // have to be extracted manually from the bundle name.
...@@ -121,6 +132,7 @@ function comment_entity_info(&$info) { ...@@ -121,6 +132,7 @@ function comment_entity_info(&$info) {
), ),
); );
} }
return $bundles;
} }
/** /**
...@@ -289,7 +301,7 @@ function comment_menu_alter(&$items) { ...@@ -289,7 +301,7 @@ function comment_menu_alter(&$items) {
$items['admin/content']['description'] = 'Administer content and comments.'; $items['admin/content']['description'] = 'Administer content and comments.';
// Adjust the Field UI tabs on admin/structure/types/manage/[node-type]. // Adjust the Field UI tabs on admin/structure/types/manage/[node-type].
// See comment_entity_info(). // See comment_entity_bundle_info().
$items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields'; $items['admin/structure/types/manage/%comment_node_type/comment/fields']['title'] = 'Comment fields';
$items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3; $items['admin/structure/types/manage/%comment_node_type/comment/fields']['weight'] = 3;
$items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display'; $items['admin/structure/types/manage/%comment_node_type/comment/display']['title'] = 'Comment display';
...@@ -1389,7 +1401,7 @@ function comment_delete_multiple($cids) { ...@@ -1389,7 +1401,7 @@ function comment_delete_multiple($cids) {
* (optional) An array of entity IDs. If omitted, all entities are loaded. * (optional) An array of entity IDs. If omitted, all entities are loaded.
* @param bool $reset * @param bool $reset
* Whether to reset the internal static entity cache. Note that the static * Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default. * cache is disabled by default.
* *
* @return array * @return array
* An array of comment objects, indexed by comment ID. * An array of comment objects, indexed by comment ID.
...@@ -1408,7 +1420,7 @@ function comment_load_multiple(array $cids = NULL, $reset = FALSE) { ...@@ -1408,7 +1420,7 @@ function comment_load_multiple(array $cids = NULL, $reset = FALSE) {
* The ID of the comment to be loaded. * The ID of the comment to be loaded.
* @param bool $reset * @param bool $reset
* Whether to reset the internal static entity cache. Note that the static * Whether to reset the internal static entity cache. Note that the static
* cache is disabled in comment_entity_info() by default. * cache is disabled by default.
* *
* @return * @return
* The comment object. * The comment object.
......
...@@ -35,12 +35,6 @@ ...@@ -35,12 +35,6 @@
* "bundle" = "node_type", * "bundle" = "node_type",
* "label" = "subject", * "label" = "subject",
* "uuid" = "uuid" * "uuid" = "uuid"
* },
* view_modes = {
* "full" = {
* "label" = "Full comment",
* "custom_settings" = FALSE
* }
* } * }
* ) * )
*/ */
......
...@@ -77,12 +77,10 @@ function pre_render($result) { ...@@ -77,12 +77,10 @@ function pre_render($result) {
* in views_plugin_row_comment|node_rss.inc * in views_plugin_row_comment|node_rss.inc
*/ */
function options_form_summary_options() { function options_form_summary_options() {
$entity_info = entity_get_info('node'); $view_modes = entity_get_view_modes('node');
$options = array(); $options = array();
if (!empty($entity_info['view_modes'])) { foreach ($view_modes as $mode => $settings) {
foreach ($entity_info['view_modes'] as $mode => $settings) { $options[$mode] = $settings['label'];
$options[$mode] = $settings['label'];
}
} }
$options['title'] = t('Title only'); $options['title'] = t('Title only');
$options['default'] = t('Use site default RSS settings'); $options['default'] = t('Use site default RSS settings');
......
...@@ -174,12 +174,13 @@ function _contact_personal_tab_access($account) { ...@@ -174,12 +174,13 @@ function _contact_personal_tab_access($account) {
} }
/** /**
* Implements hook_entity_info(). * Implements hook_entity_bundle_info().
*/ */
function contact_entity_info(&$types) { function contact_entity_bundle_info() {
$bundles = array();
foreach (config_get_storage_names_with_prefix('contact.category.') as $config_name) { foreach (config_get_storage_names_with_prefix('contact.category.') as $config_name) {
$config = config($config_name); $config = config($config_name);
$types['contact_message']['bundles'][$config->get('id')] = array( $bundles['contact_message'][$config->get('id')] = array(
'label' => $config->get('label'), 'label' => $config->get('label'),
'admin' => array( 'admin' => array(
'path' => 'admin/structure/contact/manage/%contact_category', 'path' => 'admin/structure/contact/manage/%contact_category',
...@@ -189,6 +190,7 @@ function contact_entity_info(&$types) { ...@@ -189,6 +190,7 @@ function contact_entity_info(&$types) {
), ),
); );
} }
return $bundles;
} }
/** /**
...@@ -196,8 +198,7 @@ function contact_entity_info(&$types) { ...@@ -196,8 +198,7 @@ function contact_entity_info(&$types) {
*/ */
function contact_field_extra_fields() { function contact_field_extra_fields() {
$fields = array(); $fields = array();
$entity_info = entity_get_info('contact_message'); foreach (array_keys(entity_get_bundles('contact_message')) as $bundle) {
foreach (array_keys($entity_info['bundles']) as $bundle) {
$fields['contact_message'][$bundle]['form']['name'] = array( $fields['contact_message'][$bundle]['form']['name'] = array(
'label' => t('Sender name'), 'label' => t('Sender name'),
'description' => t('Text'), 'description' => t('Text'),
......
...@@ -275,31 +275,6 @@ function field_info_storage_types($storage_type = NULL) { ...@@ -275,31 +275,6 @@ function field_info_storage_types($storage_type = NULL) {
} }
} }
/**
* Returns information about existing bundles.
*
* @param $entity_type
* The type of entity; e.g. 'node' or 'user'.
*
* @return
* An array of bundles for the $entity_type keyed by bundle name, or, if no
* $entity_type was provided, the array of all existing bundles, keyed by
* entity type.
*/
function field_info_bundles($entity_type = NULL) {
$info = entity_get_info();
if ($entity_type) {
return isset($info[$entity_type]['bundles']) ? $info[$entity_type]['bundles'] : array();
}
$bundles = array();
foreach ($info as $type => $entity_info) {
$bundles[$type] = $entity_info['bundles'];
}
return $bundles;
}
/** /**
* Returns all field definitions. * Returns all field definitions.
* *
......
...@@ -746,8 +746,8 @@ function field_view_mode_settings($entity_type, $bundle) { ...@@ -746,8 +746,8 @@ function field_view_mode_settings($entity_type, $bundle) {
// Include view modes for which nothing has been stored yet, but whose // Include view modes for which nothing has been stored yet, but whose
// definition in hook_entity_info_alter() specify they should use custom // definition in hook_entity_info_alter() specify they should use custom
// settings by default. // settings by default.
$entity_info = entity_get_info($entity_type); $view_modes = entity_get_view_modes($entity_type);
foreach ($entity_info['view_modes'] as $view_mode => $view_mode_info) { foreach ($view_modes as $view_mode => $view_mode_info) {
if (!isset($settings[$view_mode]['custom_settings']) && $view_mode_info['custom_settings']) { if (!isset($settings[$view_mode]['custom_settings']) && $view_mode_info['custom_settings']) {
$settings[$view_mode]['custom_settings'] = TRUE; $settings[$view_mode]['custom_settings'] = TRUE;
} }
......
...@@ -19,8 +19,17 @@ function field_test_entity_info_alter(&$entity_info) { ...@@ -19,8 +19,17 @@ function field_test_entity_info_alter(&$entity_info) {
// Disable the entity type translation handler. // Disable the entity type translation handler.
foreach ($entity_info as $entity_type => $info) { foreach ($entity_info as $entity_type => $info) {
$entity_info[$entity_type]['translation'][$entity_type] = FALSE; $entity_info[$entity_type]['translation'][$entity_type] = FALSE;
if ($info['module'] == 'field_test') { }
$entity_info[$entity_type]['view_modes'] = array( }
/**
* Implements hook_entity_view_mode_info_alter().
*/
function field_test_entity_view_mode_info_alter(&$view_modes) {
$entity_info = entity_get_info();
foreach ($entity_info as $entity_type => $info) {
if ($entity_info[$entity_type]['module'] == 'field_test') {
$view_modes[$entity_type] = array(
'full' => array( 'full' => array(
'label' => t('Full object'), 'label' => t('Full object'),
'custom_settings' => TRUE, 'custom_settings' => TRUE,
...@@ -30,12 +39,23 @@ function field_test_entity_info_alter(&$entity_info) { ...@@ -30,12 +39,23 @@ function field_test_entity_info_alter(&$entity_info) {
'custom_settings' => TRUE, 'custom_settings' => TRUE,
), ),
); );
$entity_info[$entity_type]['bundles'] = state()->get('field_test_bundles') ?: array('test_bundle' => array('label' => 'Test Bundle')); }
}
}
/**
* Implements hook_entity_bundle_info_alter().
*/
function field_test_entity_bundle_info_alter(&$bundles) {
$entity_info = entity_get_info();
foreach ($bundles as $entity_type => $info) {
if ($entity_info[$entity_type]['module'] == 'field_test') {
$bundles[$entity_type] = state()->get('field_test_bundles') ?: array('test_bundle' => array('label' => 'Test Bundle'));
if ($entity_type == 'test_entity_bundle') { if ($entity_type == 'test_entity_bundle') {
$entity_info[$entity_type]['bundles'] += array('test_entity_2' => array('label' => 'Test entity 2')); $bundles[$entity_type] += array('test_entity_2' => array('label' => 'Test entity 2'));
} }
if ($entity_type == 'test_entity_bundle_key') { if ($entity_type == 'test_entity_bundle_key') {
$entity_info[$entity_type]['bundles'] += array('bundle1' => array('label' => 'Bundle1'), 'bundle2' => array('label' => 'Bundle2')); $bundles[$entity_type] += array('bundle1' => array('label' => 'Bundle1'), 'bundle2' => array('label' => 'Bundle2'));
} }
} }
} }
......
...@@ -45,9 +45,8 @@ function field_test_permission() { ...@@ -45,9 +45,8 @@ function field_test_permission() {
*/ */
function field_test_menu() { function field_test_menu() {
$items = array(); $items = array();
$bundles = field_info_bundles('test_entity');
foreach ($bundles as $bundle_name => $bundle_info) { foreach (entity_get_bundles('test_entity') as $bundle_name => $bundle_info) {
$items['test-entity/add/' . $bundle_name] = array( $items['test-entity/add/' . $bundle_name] = array(
'title' => t('Add %bundle test_entity', array('%bundle' => $bundle_info['label'])), 'title' => t('Add %bundle test_entity', array('%bundle' => $bundle_info['label'])),
'page callback' => 'field_test_entity_add', 'page callback' => 'field_test_entity_add',
...@@ -309,7 +308,7 @@ function field_test_field_extra_fields_alter(&$info) { ...@@ -309,7 +308,7 @@ function field_test_field_extra_fields_alter(&$info) {
* @todo Remove when http://drupal.org/node/1822458 is fixed. * @todo Remove when http://drupal.org/node/1822458 is fixed.
*/ */
function field_test_module_implements_alter(&$implementations, $hook) { function field_test_module_implements_alter(&$implementations, $hook) {
if ($hook == 'entity_info_alter' && isset($implementations['field_test']) && isset($implementations['rdf'])) { if ($hook == 'entity_bundle_info_alter' && isset($implementations['field_test']) && isset($implementations['rdf'])) {
foreach (array('field_test', 'rdf') as $module) { foreach (array('field_test', 'rdf') as $module) {
$group = $implementations[$module]; $group = $implementations[$module];
unset($implementations[$module]); unset($implementations[$module]);
......
...@@ -174,8 +174,7 @@ function addField($field, $type, $langcode) { ...@@ -174,8 +174,7 @@ function addField($field, $type, $langcode) {
// If there are bundles, pick one. It does not matter which, // If there are bundles, pick one. It does not matter which,
// properties exist on all bundles. // properties exist on all bundles.
if (!empty($entity_info['entity keys']['bundle'])) { if (!empty($entity_info['entity keys']['bundle'])) {
$bundles = array_keys($entity_info['bundles']); $values[$entity_info['entity keys']['bundle']] = key(entity_get_bundles('node'));
$values[$entity_info['entity keys']['bundle']] = reset($bundles);
} }
$entity = entity_create($entity_type, $values); $entity = entity_create($entity_type, $values);
$propertyDefinitions = $entity->$specifier->getPropertyDefinitions(); $propertyDefinitions = $entity->$specifier->getPropertyDefinitions();
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
function field_ui_fields_list() { function field_ui_fields_list() {
$instances = field_info_instances(); $instances = field_info_instances();
$field_types = field_info_field_types(); $field_types = field_info_field_types();
$bundles = field_info_bundles();