public function ContentEntitySource::continuousSettingsForm

Creates "Continuous settings" form element.

Parameters

array $form: The job form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

\Drupal\tmgmt\Entity\Job $job: Continuous job.

Return value

array Continuous settings form elements

Overrides ContinuousSourceInterface::continuousSettingsForm

File

sources/content/src/Plugin/tmgmt/Source/ContentEntitySource.php, line 670

Class

ContentEntitySource
Content entity source plugin controller.

Namespace

Drupal\tmgmt_content\Plugin\tmgmt\Source

Code

public function continuousSettingsForm(array &$form, FormStateInterface $form_state, Job $job) {
  $continuous_settings = $job
    ->getContinuousSettings();
  $element = array();
  $item_types = $this
    ->getItemTypes();
  asort($item_types);
  $entity_type_manager = \Drupal::entityTypeManager();
  foreach ($item_types as $item_type => $item_type_label) {
    $entity_type = $entity_type_manager
      ->getDefinition($item_type);
    $element[$entity_type
      ->id()]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => $item_type_label,
      '#default_value' => isset($continuous_settings[$this
        ->getPluginId()][$entity_type
        ->id()]) ? $continuous_settings[$this
        ->getPluginId()][$entity_type
        ->id()]['enabled'] : FALSE,
    );
    if ($entity_type
      ->hasKey('bundle')) {
      $bundles = \Drupal::service('entity_type.bundle.info')
        ->getBundleInfo($item_type);
      $element[$entity_type
        ->id()]['bundles'] = array(
        '#title' => $this
          ->getBundleLabel($entity_type),
        '#type' => 'details',
        '#open' => TRUE,
        '#states' => array(
          'invisible' => array(
            'input[name="continuous_settings[' . $this
              ->getPluginId() . '][' . $entity_type
              ->id() . '][enabled]"]' => array(
              'checked' => FALSE,
            ),
          ),
        ),
      );
      foreach ($bundles as $bundle => $bundle_label) {
        if (\Drupal::service('content_translation.manager')
          ->isEnabled($entity_type
          ->id(), $bundle)) {
          $element[$entity_type
            ->id()]['bundles'][$bundle] = array(
            '#type' => 'checkbox',
            '#title' => $bundle_label['label'],
            '#default_value' => isset($continuous_settings[$this
              ->getPluginId()][$entity_type
              ->id()]['bundles'][$bundle]) ? $continuous_settings[$this
              ->getPluginId()][$entity_type
              ->id()]['bundles'][$bundle] : FALSE,
          );
        }
      }
    }
  }
  return $element;
}