Same filename and directory in other branches
  1. 8.x-1.x src/Services/EntityCloneServiceProvider.php 1 comment

Namespace

Drupal\entity_clone\Services

File

src/Services/EntityCloneServiceProvider.php

View source
<?php

namespace Drupal\entity_clone\Services;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\EntityOwnerTrait;

/**
 * Service Provider Class.
 */
class EntityCloneServiceProvider {
    
    /**
     * The entity type manager.
     *
     * @var \Drupal\Core\Entity\EntityTypeInterface
     */
    protected $entityType;
    
    /**
     * Constructs a new ServiceProvider object.
     */
    public function __construct() {
    }
    
    /**
     * Checks if the given entity implements has owner trait.
     *
     * @param \Drupal\Core\Entity\EntityTypeInterface $entityType
     *   Entity to be tested.
     *
     * @return bool
     *   Returns boolean for the owner trait test.
     */
    public function entityTypeHasOwnerTrait(EntityTypeInterface $entityType) {
        try {
            $reflectionClass = new \ReflectionClass($entityType->getOriginalClass());
        } catch (\ReflectionException $e) {
            return FALSE;
        }
        return in_array(EntityOwnerTrait::class, array_keys($reflectionClass->getTraits()));
    }

}

Classes

Title Deprecated Summary
EntityCloneServiceProvider Service Provider Class.