/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { // Get the custom entity ID. $custom_entity_id = $this->entity->getEntityType()->getBundleOf(); $entities = $this->queryFactory->get($custom_entity_id)->condition('type', $this->entity->id())->execute(); if (!empty($entities)) { $caption = '<p>' . $this->formatPlural(count($entities), '%label is used by 1 entity on your site. You can not remove this entity type until you have removed all of the %label entities.', '%label is used by @count entities on your site. You may not remove %label until you have removed all of the %label entities.', ['%label' => $this->entity->label()]) . '</p>'; $form['description'] = array('#markup' => $caption); return $form; } else { return parent::buildForm($form, $form_state); } }
/** * Provides the page title for the entity form. * * @param \Drupal\Core\Entity\ContentEntityTypeInterface $entity_definition * The custom entity definition. * @param \Drupal\content_entity_base\Entity\EntityTypeBaseInterface $entity_bundle * The custom entity type bundle to use. * * @return string * The page title. */ public function getAddFormTitle(ContentEntityTypeInterface $entity_definition = NULL, EntityTypeBaseInterface $entity_bundle = NULL) { // Build the form page title using the type. return $this->t('Add %type @entity_label', ['@entity_label' => $entity_definition->getLabel(), '%type' => $entity_bundle ? $entity_bundle->label() : 'Invalid Bundle']); }
/** * Builds a standard list of entity permissions for a given type. * * @param \Drupal\content_entity_base\Entity\EntityTypeBaseInterface $type * The machine name of the entity type. * * @return array * An array of permission names and descriptions. */ protected function buildPermissions(EntityTypeBaseInterface $type) { $entity_id = $type->bundleOf(); // Get the referring entity definition. $entity_definition = $this->entityManager->getDefinition($entity_id); $type_id = $type->id(); $type_params = ['%entity_label' => $entity_definition->getLabel(), '%type_name' => $type->label()]; return ["create {$type_id} {$entity_id}" => ['title' => $this->t('%type_name: Create new %entity_label', $type_params)], "edit own {$type_id} {$entity_id}" => ['title' => $this->t('%type_name: Edit own %entity_label', $type_params)], "edit any {$type_id} {$entity_id}" => ['title' => $this->t('%type_name: Edit any %entity_label', $type_params)], "delete own {$type_id} {$entity_id}" => ['title' => $this->t('%type_name: Delete own %entity_label', $type_params)], "delete any {$type_id} {$entity_id}" => ['title' => $this->t('%type_name: Delete any %entity_label', $type_params)], "view {$type_id} {$entity_id} revisions" => ['title' => $this->t('%type_name: View %entity_label revisions', $type_params)], "revert {$type_id} {$entity_id} revisions" => ['title' => $this->t('%type_name: Revert %entity_label revisions', $type_params), 'description' => t('Role requires permission <em>view revisions</em> and <em>edit rights</em> for %entity_label in question, or <em>Administer %entity_label</em>.', $type_params)], "delete {$type_id} {$entity_id} revisions" => ['title' => $this->t('%type_name: Delete %entity_label revisions', $type_params), 'description' => $this->t('Role requires permission to <em>view revisions</em> and <em>delete rights</em> for %entity_label in question, or <em>Administer %entity_label</em>.', $type_params)]]; }