3
0
Fork 0
mirror of https://github.com/farmOS/farmOS.git synced 2024-02-23 11:37:38 +01:00

Deny access to the entity type add form.

This commit is contained in:
paul121 2021-02-16 17:12:38 -08:00 committed by Michael Stenta
parent 768c6ec0bf
commit 02de4ba117
2 changed files with 35 additions and 0 deletions

View file

@ -8,6 +8,7 @@
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\EntityViewsData;
use Drupal\farm_entity\BundlePlugin\FarmEntityBundlePluginHandler;
use Drupal\farm_entity\Routing\DefaultHtmlRouteProvider;
/**
* Implements hook_module_implements_alter().
@ -36,6 +37,14 @@ function farm_entity_entity_type_build(array &$entity_types) {
if (!empty($entity_types[$entity_type])) {
$entity_types[$entity_type]->set('bundle_plugin_type', $entity_type . '_type');
$entity_types[$entity_type]->setHandlerClass('bundle_plugin', FarmEntityBundlePluginHandler::class);
// Deny access to the entity type add form. New entity types of entities
// with bundle plugins cannot be created in the UI.
// See https://www.drupal.org/project/farm/issues/3196423
$bundle_entity_type = $entity_types[$entity_type]->getBundleEntityType();
$route_providers = $entity_types[$bundle_entity_type]->getRouteProviderClasses();
$route_providers['default'] = DefaultHtmlRouteProvider::class;
$entity_types[$bundle_entity_type]->setHandlerClass('route_provider', $route_providers);
}
}

View file

@ -0,0 +1,26 @@
<?php
namespace Drupal\farm_entity\Routing;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\Routing\DefaultHtmlRouteProvider as EntityDefaultHtmlRouteProvider;
/**
* Deny access to the entity type add form.
*
* New entity types of entities with bundle plugins cannot be created in the UI.
*
* @See https://www.drupal.org/project/farm/issues/3196423
*/
class DefaultHtmlRouteProvider extends EntityDefaultHtmlRouteProvider {
/**
* {@inheritdoc}
*/
protected function getAddFormRoute(EntityTypeInterface $entity_type) {
$route = parent::getAddFormRoute($entity_type);
$route->setRequirement('_access', 'FALSE');
return $route;
}
}