Same name and namespace in other branches
- 8.x-1.x entity_clone.module \entity_clone_entity_type_build()
Implements hook_entity_type_build().
File
-
./
entity_clone.module, line 49
Code
function entity_clone_entity_type_build(array &$entity_types) {
$specific_handler = [
'file' => [
'entity_clone' => FileEntityClone::class,
],
'user' => [
'entity_clone' => UserEntityClone::class,
],
'field_config' => [
'entity_clone' => FieldConfigEntityClone::class,
],
'node_type' => [
'entity_clone' => ConfigWithFieldEntityClone::class,
],
'comment_type' => [
'entity_clone' => ConfigWithFieldEntityClone::class,
],
'block_content_type' => [
'entity_clone' => ConfigWithFieldEntityClone::class,
],
'contact_form' => [
'entity_clone' => ConfigWithFieldEntityClone::class,
],
'taxonomy_term' => [
'entity_clone' => TaxonomyTermEntityClone::class,
],
'menu' => [
'entity_clone_form' => MenuEntityCloneForm::class,
'entity_clone' => MenuEntityClone::class,
],
'taxonomy_vocabulary' => [
'entity_clone' => ConfigWithFieldEntityClone::class,
],
'entity_view_display' => [
'entity_clone' => \Drupal::moduleHandler()->moduleExists('layout_builder') ? LayoutBuilderEntityClone::class : NULL,
],
];
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
foreach ($entity_types as $entity_type_id => $entity_type) {
$has_entity_clone_handler = $entity_type->getHandlerClass('entity_clone');
if (!$has_entity_clone_handler) {
if ($entity_type instanceof ContentEntityTypeInterface) {
$entity_type->setHandlerClass('entity_clone', ContentEntityCloneBase::class);
$entity_type->setHandlerClass('entity_clone_form', ContentEntityCloneFormBase::class);
}
elseif ($entity_type instanceof ConfigEntityTypeInterface) {
$entity_type->setHandlerClass('entity_clone', ConfigEntityCloneBase::class);
$entity_type->setHandlerClass('entity_clone_form', ConfigEntityCloneFormBase::class);
}
}
if (isset($specific_handler[$entity_type->id()]['entity_clone'])) {
$entity_type->setHandlerClass('entity_clone', $specific_handler[$entity_type->id()]['entity_clone']);
}
if (isset($specific_handler[$entity_type->id()]['entity_clone_form'])) {
$entity_type->setHandlerClass('entity_clone_form', $specific_handler[$entity_type->id()]['entity_clone_form']);
}
$entity_type->setLinkTemplate('clone-form', "/entity_clone/{$entity_type_id}/{{$entity_type_id}}");
}
}