Esempio n. 1
0
  /**
   * Get update runner for scheduled update types.
   *
   * @param array $update_types
   *  Update ids to load runners for. If empty return all.
   *
   * @return \Drupal\scheduled_updates\Plugin\UpdateRunnerInterface[]
   */
  protected function getUpdateTypeRunners(array $update_types = []) {
    $bundles = $this->entityTypeBundleInfo->getBundleInfo('scheduled_update');
    /** @var UpdateRunnerInterface[] $runners */
    $runners = [];
    foreach ($bundles as $bundle => $bundle_info) {
      if (empty($update_types) || in_array($bundle, $update_types)) {
        /** @var ScheduledUpdateType $updater */
        $updater = ScheduledUpdateType::load($bundle);

        if ($runner = $this->getUpdateRunnerInstance($updater)) {
          $runners[$bundle] = $runner;
        }
        else {
          // @todo User logger for missing plugins
          /* drupal_set_message(t('Missing plugin in @plugin_id in update type @type',
            [
              '@plugin_id' => $runner_settings['id'],
              '@type' => $updater->label(),
            ])); */
        }
      }
    }
    return $runners;

  }
Esempio n. 2
0
  /**
   * BaseUpdateRunner constructor.
   *
   * @param array $configuration
   * @param string $plugin_id
   * @param mixed $plugin_definition
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $fieldManager
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   * @param \Drupal\scheduled_updates\UpdateUtils $updateUtils
   * @param \Drupal\Core\Session\AccountSwitcherInterface $accountSwitcher
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityFieldManagerInterface $fieldManager, EntityTypeManagerInterface $entityTypeManager, UpdateUtils $updateUtils, AccountSwitcherInterface $accountSwitcher) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->fieldManager = $fieldManager;
    $this->entityTypeManager = $entityTypeManager;
    $this->updateUtils = $updateUtils;
    $this->accountSwitcher = $accountSwitcher;
    if (!empty($configuration['updater_type'])) {
      $this->scheduled_update_type = ScheduledUpdateType::load($configuration['updater_type']);
    }

  }
 /**
  * {@inheritdoc}
  */
 public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions)
 {
     /** @var ScheduledUpdateType $update_type */
     if ($update_type = ScheduledUpdateType::load($bundle)) {
         $fields['entity_ids'] = clone $base_field_definitions['entity_ids'];
         if ($update_type->isIndependentType()) {
             // @todo Update other setting per bundle: cardinality, required, default display etc.
             // @todo Add reference field settings on Type edit page
             $fields['entity_ids']->setSetting('target_type', $update_type->getUpdateEntityType());
             $fields['entity_ids']->setDisplayOptions('form', array('type' => 'entity_reference_autocomplete', 'weight' => -10));
         } else {
             $fields['entity_ids']->setDisplayConfigurable('form', FALSE);
         }
         return $fields;
     }
     return array();
 }
 /**
  * Create an update type name programmatically.
  *
  * @param $entity_type
  * @param $clone_field
  *
  * @return string
  */
 protected function createNewUpdateTypeName($entity_type, $clone_field) {
   $name = $entity_type . '__' . $clone_field;
   $suffix = 0;
   $new_name = $name;
   while (ScheduledUpdateType::load($new_name)) {
     $suffix++;
     $new_name = $name . '_' . $suffix;
   }
   return $new_name;
 }
Esempio n. 5
0
  /**
   * {@inheritdoc}
   */
  public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
    /** @var ScheduledUpdateType $update_type */
    if ($update_type = ScheduledUpdateType::load($bundle)) {
      $fields['entity_ids'] = clone $base_field_definitions['entity_ids'];

      /** @var BaseFieldDefinition $definition */
      $definition =& $fields['entity_ids'];

      if ($update_type->isIndependentType()) {


        // @todo Update other setting per bundle: cardinality, required, default display etc.
        // @todo Add reference field settings on Type edit page
        $definition->setSetting('target_type', $update_type->getUpdateEntityType());
        $definition->setDisplayOptions('form', array(
          'type' => 'entity_reference_autocomplete',
          'weight' => -10,
        ));
        $runner_settings = $update_type->getUpdateRunnerSettings();
        if (isset($runner_settings['bundles'])) {
          $bundles = array_filter($runner_settings['bundles']);
          $definition->setSetting('handler_settings', ['target_bundles' => $bundles]);
        }
      }
      else {
        $definition->setDisplayConfigurable('form', FALSE);
        $definition->setDisplayConfigurable('view', FALSE);
      }

      return $fields;
    }
    return array();
  }