-
Add a src/Controller/EventTypeListBuilder.php file with the following:
<?php
namespace Drupal\event\Controller;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
class EventTypeListBuilder extends EntityListBuilder {
public function buildHeader() {
$header = [];
$header['label'] = $this->t('Label');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$row = [];
$row['label'] = $entity->label();
return $row + parent::buildRow($entity);
}
}
-
Add the following use statements to src/Entity/EventType.php:
use Drupal\entity\EntityAccessControlHandler;
use Drupal\event\Controller\EventTypeListBuilder;
use Drupal\entity\Menu\EntityCollectionLocalActionProvider;
use Drupal\entity\EntityPermissionProvider;
use Drupal\entity\Routing\DefaultHtmlRouteProvider;
-
Add the following to the attributes in src/Entity/EventType.php:
handlers: [
'access' => EntityAccessControlHandler::class,
'list_builder' => EventTypeListBuilder::class,
'local_action_provider' => [
'collection' => EntityCollectionLocalActionProvider::class,
],
'permission_provider' => EntityPermissionProvider::class,
'route_provider' => [
'default' => DefaultHtmlRouteProvider::class,
],
],
links: [
'collection' => '/admin/structure/event-types',
],
admin_permission: 'administer event type',
-
Add the following to event.links.menu.yml:
entity.event_type.collection:
title: 'Event types'
route_name: entity.event_type.collection
parent: system.admin_structure
-
Rebuild caches
Run drush cache:rebuild
-
Verify that there is a Event types menu link in the toolbar menu
-
Visit /admin/structure/event-types
Note that a listing of event types is shown.
In contrast to content entities, configuration entities do not have the ability
to use widgets for their forms, so we need to provide the respective form
elements ourselves.
-
Add the following use statements to src/Entity/EventType.php:
use Drupal\event\Form\EventTypeForm;
use Drupal\Core\Entity\EntityDeleteForm;
-
Add the following to the handlers section of the attributes in
src/Entity/EventType.php:
'form' => [
'add' => EventTypeForm::class,
'edit' => EventTypeForm::class,
'delete' => EntityDeleteForm::class,
]
-
Add the following to the links section of the attributes in
src/Entity/EventType.php:
'add-form' => '/admin/structure/event-types/add',
'edit-form' => '/admin/structure/event-types/manage/{event_type}',
'delete-form' => '/admin/structure/event-types/manage/{event_type}/delete',
-
Add the following to event.links.task.yml:
entity.event_type.edit_form:
title: 'Edit'
route_name: entity.event_type.edit_form
base_route: entity.event_type.edit_form
entity.event_type.delete_form:
title: 'Delete'
route_name: entity.event_type.delete_form
base_route: entity.event_type.edit_form
-
Rebuild caches
Run drush cache:rebuild
-
Verify that a local action appears to add an event type
-
Add an event type.
-
Edit an event type.
-
Verify that Edit and Delete local tasks are shown.
-
Delete an event type.