/** * Gets the title for the "Entity Add" page. * * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_definition * The custom entity definition. * * @return string * The title customized for this entity type. */ public function getAddPageTitle(ContentEntityTypeInterface $entity_definition = NULL) { // Get the storage controller for this entity. $bundle_storage = $entity_definition ? $this->entityManager()->getStorage($entity_definition->getBundleEntityType()) : NULL; // Load all entity types for this entity definition. $types = $bundle_storage->loadMultiple(); // Check for existing types. $entity_bundle = $types && count($types) == 1 ? reset($types) : FALSE; return $this->t($entity_bundle ? 'Add %type @entity_label content' : 'Add @entity_label', ['@entity_label' => $entity_definition->getLabel(), '%type' => $entity_bundle ? $entity_bundle->label() : '']); }
/** * Gets an array of entity type permissions. * * @param ContentEntityTypeInterface $entity_type * The custom entity definition. * * @return array * The entity type permissions. * * @see \Drupal\user\PermissionHandlerInterface::getPermissions() */ public function entityPermissions(ContentEntityTypeInterface $entity_type = NULL) { $perms = []; if (!empty($entity_type)) { // Get the entity ID. $entity_type_id = $entity_type->id(); // Build replacement data for lables and descriptions. $replacements = ['@entity_type_id' => $entity_type_id, '@entity_label' => $entity_type->getLabel()]; // Add the default entity permissions. $perms = ["bypass {$entity_type_id} access" => ['title' => $this->t('Bypass @entity_label access control', $replacements), 'description' => $this->t('View, edit and delete all @entity_label regardless of permission restrictions.', $replacements), 'restrict access' => TRUE], "administer {$entity_type_id} types" => ['title' => $this->t('Administer @entity_label types', $replacements), 'description' => $this->t('Promote, change ownership, edit revisions, and perform other tasks across all @entity_label types.', $replacements), 'restrict access' => TRUE], "administer {$entity_type_id}" => ['title' => $this->t('Administer @entity_label', $replacements), 'restrict access' => TRUE], "access {$entity_type_id} overview" => ['title' => $this->t('Access the @entity_label overview page', $replacements), 'description' => $this->t('Get an overview of all @entity_label.', $replacements)], "access {$entity_type_id}" => ['title' => $this->t('View published @entity_label', $replacements)], "view own unpublished {$entity_type_id}" => ['title' => $this->t('View own unpublished @entity_label', $replacements)], "view all {$entity_type_id} revisions" => ['title' => $this->t('View all @entity_label revisions', $replacements)], "revert all {$entity_type_id} revisions" => ['title' => $this->t('Revert all @entity_label revisions', $replacements), 'description' => $this->t('Role requires permission <em>View all @entity_label revisions</em> and <em>edit rights</em> for @entity_label in question or <em>Administer @entity_label</em>.', $replacements)], "delete all {$entity_type_id} revisions" => ['title' => $this->t('Delete all @entity_label revisions', $replacements), 'description' => $this->t('Role requires permission to <em>View all @entity_label revisions</em> and <em>delete rights</em> for @entity_label in question or <em>Administer @entity_label</em>.', $replacements)]]; // Load bundles if any are defined. if (($entity_type_storage = $this->entityManager->getStorage($entity_type->getBundleEntityType())) && ($entity_types = $entity_type_storage->loadMultiple())) { // Generate entity permissions for all types for this entity. foreach ($entity_types as $type) { $perms += $this->buildPermissions($type); } } } return $perms; }
/** * Returns the base field definitions for entity keys. * * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type * The entity type. * * @return \Drupal\Core\Field\BaseFieldDefinition[] */ protected static function entityKeysBaseFieldDefinitions(ContentEntityTypeInterface $entity_type) { $fields = []; if ($entity_type->hasKey('id')) { $fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')->setLabel(t('ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE); } if ($entity_type->hasKey('uuid')) { $fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')->setLabel(t('UUID'))->setReadOnly(TRUE); } if ($entity_type->hasKey('revision')) { $fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')->setLabel(t('Revision ID'))->setReadOnly(TRUE)->setSetting('unsigned', TRUE); } if ($entity_type->hasKey('langcode')) { $fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')->setLabel(t('Language'))->setTranslatable(TRUE)->setRevisionable(TRUE)->setDisplayOptions('view', ['type' => 'hidden'])->setDisplayOptions('form', ['type' => 'language_select', 'weight' => 2]); } $bundle_entity_type_id = $entity_type->getBundleEntityType(); if ($bundle_entity_type_id && $entity_type->hasKey('bundle')) { $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference')->setLabel(t('Type'))->setSetting('target_type', $bundle_entity_type_id)->setReadOnly(TRUE); } return $fields; }