You are here

content_type_clone.module in Content Type Clone 8

Same filename and directory in other branches
  1. 7 content_type_clone.module

Allows to clone content types from a simple link added to each content type in the content type list at admin/structure/types

File

content_type_clone.module
View source
<?php

/**
 * @file
 * Allows to clone content types from a simple link added to each content type
 * in the content type list at admin/structure/types
 */
use Drupal\Core\Url;
use Drupal\Core\Entity\EntityInterface;

/**
 * Alter entity operations.
 *
 * @param array $operations
 *   Operations array as returned by
 *   \Drupal\Core\Entity\EntityStorageControllerInterface::getOperations().
 * @param \Drupal\Core\Entity\EntityInterface $entity
 *   The entity on which the linked operations will be performed.
 */
function content_type_clone_entity_operation_alter(array &$operations, EntityInterface $entity) {

  //Get the entity info.
  $info = $entity
    ->getEntityType();

  //Get the entity bundle.
  $bundle_of = $info
    ->getBundleOf();

  //Get the user account.
  $account = \Drupal::currentUser();

  //Add the clone link to operations.
  if ($account
    ->hasPermission('administer content') && $bundle_of === 'node') {
    $operations['clone'] = [
      'title' => t('Clone'),
      'weight' => 30,
      'url' => Url::fromRoute("content_type_clone.clone_content_type", [
        $entity
          ->getEntityTypeId() => $entity
          ->id(),
      ]),
    ];
  }
}

Functions

Namesort descending Description
content_type_clone_entity_operation_alter Alter entity operations.