class EntityCollectionLocalActionProvider in Entity API 8
Provides a action link to the add page or add form on the collection.
Hierarchy
- class \Drupal\entity\Menu\EntityCollectionLocalActionProvider implements EntityHandlerInterface, EntityLocalActionProviderInterface uses StringTranslationTrait
Expanded class hierarchy of EntityCollectionLocalActionProvider
File
- src/
Menu/ EntityCollectionLocalActionProvider.php, line 14
Namespace
Drupal\entity\MenuView source
class EntityCollectionLocalActionProvider implements EntityLocalActionProviderInterface, EntityHandlerInterface {
use StringTranslationTrait;
/**
* Constructs a new EntityCollectionLocalActionProvider object.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct(EntityTypeInterface $entity_type, TranslationInterface $string_translation) {
$this
->setStringTranslation($string_translation);
}
/**
* {@inheritdoc}
*/
public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
return new static($entity_type, $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function buildLocalActions(EntityTypeInterface $entity_type) {
$actions = [];
if ($entity_type
->hasLinkTemplate('collection')) {
$entity_type_id = $entity_type
->id();
if ($entity_type
->hasLinkTemplate('add-page')) {
$route_name = "entity.{$entity_type_id}.add_page";
}
elseif ($entity_type
->hasLinkTemplate('add-form')) {
$route_name = "entity.{$entity_type_id}.add_form";
}
if (isset($route_name)) {
$actions[$route_name] = [
'title' => $this
->t('Add @entity', [
'@entity' => $entity_type
->getSingularLabel(),
]),
'route_name' => $route_name,
'options' => [
// Redirect back to the collection after form submission.
'query' => [
'destination' => $entity_type
->getLinkTemplate('collection'),
],
],
'appears_on' => [
"entity.{$entity_type_id}.collection",
],
];
}
}
return $actions;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityCollectionLocalActionProvider:: |
public | function |
Builds local actions for the given entity type. Overrides EntityLocalActionProviderInterface:: |
|
EntityCollectionLocalActionProvider:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
EntityCollectionLocalActionProvider:: |
public | function | Constructs a new EntityCollectionLocalActionProvider object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |