Commit 2276f561 authored by Jonathan Smith's avatar Jonathan Smith Committed by Jonathan Smith
Browse files

Issue #3224263 by jonathan1055: Add $entityTypeObject property and...

Issue #3224263 by jonathan1055:  Add $entityTypeObject property and entityTypeObject() method in plugin
parent e5cf067c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ class SchedulerManager {
        $query->accessCheck(FALSE);
        // If the entity type is revisionable then make sure we look for the
        // latest revision. This is important for moderated entities.
        if ($this->entityTypeManager->getDefinition($entityTypeId)->isRevisionable()) {
        if ($plugin->entityTypeObject()->isRevisionable()) {
          $query->latestRevision();
        }
        $ids = $query->execute();
@@ -474,7 +474,7 @@ class SchedulerManager {
        $query->accessCheck(FALSE);
        // If the entity type is revisionable then make sure we look for the
        // latest revision. This is important for moderated entities.
        if ($this->entityTypeManager->getDefinition($entityTypeId)->isRevisionable()) {
        if ($plugin->entityTypeObject()->isRevisionable()) {
          $query->latestRevision();
        }
        $ids = $query->execute();
+23 −10
Original line number Diff line number Diff line
@@ -18,6 +18,13 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
   */
  protected $entityTypeManager;

  /**
   * The entity type object for this plugin.
   *
   * @var Drupal\Core\Config\Entity\ConfigEntityType
   */
  protected $entityTypeObject;

  /**
   * A static cache of create/edit entity form IDs.
   *
@@ -38,6 +45,8 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    $instance = new static($configuration, $plugin_id, $plugin_definition);
    $instance->entityTypeManager = $container->get('entity_type.manager');
    $instance->entityTypeObject = $instance->entityTypeManager
      ->getDefinition($plugin_definition['entityType']);

    return $instance;
  }
@@ -71,6 +80,16 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
    return $this->pluginDefinition['entityType'];
  }

  /**
   * Get the entity type object supported by this plugin.
   *
   * @return Drupal\Core\Config\Entity\ConfigEntityType
   *   The entity type object.
   */
  public function entityTypeObject() {
    return $this->entityTypeObject;
  }

  /**
   * Get module dependency.
   *
@@ -160,9 +179,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
   *   The name of the type/bundle field for this entity type.
   */
  public function typeFieldName() {
    return $this->entityTypeManager
      ->getDefinition($this->entityType())
      ->getKey('bundle');
    return $this->entityTypeObject->getKey('bundle');
  }

  /**
@@ -172,12 +189,10 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
   *   The type/bundle objects, keyed by type/bundle name.
   */
  public function getTypes() {
    $bundleDefinition = $this->entityTypeManager
      ->getDefinition($this->entityType())
      ->getBundleEntityType();
    $bundleEntityType = $this->entityTypeObject->getBundleEntityType();

    return $this->entityTypeManager
      ->getStorage($bundleDefinition)
      ->getStorage($bundleEntityType)
      ->loadMultiple();
  }

@@ -200,9 +215,7 @@ abstract class SchedulerPluginBase extends PluginBase implements SchedulerPlugin
      return $this->entityTypeFormIds;
    }

    $bundleEntityType = $this->entityTypeManager
      ->getDefinition($this->entityType())
      ->getBundleEntityType();
    $bundleEntityType = $this->entityTypeObject->getBundleEntityType();

    return $this->entityTypeFormIds = $this->entityFormIdsByType($bundleEntityType, TRUE);
  }