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:
parent
768c6ec0bf
commit
02de4ba117
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
26
modules/core/entity/src/Routing/DefaultHtmlRouteProvider.php
Normal file
26
modules/core/entity/src/Routing/DefaultHtmlRouteProvider.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue