diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 44c3040..fbef5e7 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -752,13 +752,24 @@ function entity_page_access(EntityInterface $entity, $operation = 'view') { * * @param string $entity_type * The entity type. + * @param string $bundle + * (optional) The bundle of the entity. Required if the entity supports + * bundles, defaults to the entity type otherwise. * * @return bool * TRUE if the access is granted. FALSE if access is denied. */ -function entity_page_create_access($entity_type) { +function entity_page_create_access($entity_type, $bundle = NULL) { + $definition = drupal_container()->get('plugin.manager.entity')->getDefinition($entity_type); + + // Pass in the entity bundle if given and required. + $values = array(); + if ($bundle && isset($definition['entity_keys']['bundle'])) { + $values[$definition['entity_keys']['bundle']] = $bundle; + } + if (isset($definition['entity_keys']['bundle'])) $entity = drupal_container()->get('plugin.manager.entity') ->getStorageController($entity_type) - ->create(array()); + ->create($values); return $entity->access('create'); } diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 4b1a2b1..832efeb 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -362,8 +362,8 @@ function taxonomy_menu() { 'title' => 'Add term', 'page callback' => 'taxonomy_term_add', 'page arguments' => array(3), - 'access callback' => 'entity_page_create_access', - 'access arguments' => array('taxonomy_term'), + 'access callback' => 'taxonomy_term_create_access', + 'access arguments' => array(3), 'type' => MENU_LOCAL_ACTION, 'file' => 'taxonomy.admin.inc', ); @@ -372,6 +372,19 @@ function taxonomy_menu() { } /** + * Access callback for creating a new taxonomy term. + * + * @param \Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary + * The vocabulary entity that represents the term bundle. + * + * @return bool + * TRUE if access is allowed, FALSE if not. + */ +function taxonomy_term_create_access(Vocabulary $vocabulary) { + return entity_page_create_access('taxonomy_term', $vocabulary->id()); +} + +/** * Implements hook_admin_paths(). */ function taxonomy_admin_paths() {