You are here

function _cms_content_sync_paragraphs_push_settings_form in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x cms_content_sync.module \_cms_content_sync_paragraphs_push_settings_form()
  2. 2.0.x cms_content_sync.module \_cms_content_sync_paragraphs_push_settings_form()

Add the Push settings for to the several Paragraph widget types.

1 call to _cms_content_sync_paragraphs_push_settings_form()
cms_content_sync_field_widget_form_alter in ./cms_content_sync.module
Add additional entity status fields to paragraph items.

File

./cms_content_sync.module, line 579
Module file for cms_content_sync.

Code

function _cms_content_sync_paragraphs_push_settings_form(&$element, FormStateInterface &$form_state, &$context) {

  // The parent entity of the paragraph.
  $parent = $context['items']
    ->getParent()
    ->getValue();

  // This code is based on:
  // https://www.drupal.org/project/paragraphs/issues/2868155#comment-12610258
  $entity_type = 'paragraph';
  if (isset($element['#paragraph_type'])) {
    $bundle = $element['#paragraph_type'];
    $delta = $context['delta'];
    if (!empty($context['items'])) {
      if (isset($context['items']
        ->get($delta)->target_id)) {
        $entity = Paragraph::load($context['items']
          ->get($delta)->target_id);
      }
    }
    if (!empty($entity)) {
      _cms_content_sync_form_alter_disabled_fields($element, $form_state, $entity);
    }

    // If no bundle is given, the previous mentioned commit is
    // not added to the project.
    if (!is_null($bundle)) {

      // If the parent entity isn't pushed, there's no need to handle these
      // paragraphs at all.
      $push_any = (bool) count(PushIntent::getFlowsForEntity($parent, PushIntent::PUSH_ANY));
      if (!$push_any && !EntityStatus::getLastPushForEntity($parent)) {
        return;
      }
      $selectable_push_flows = Pool::getSelectablePools($entity_type, $bundle, $parent, $context['items']
        ->getName());
      if (!empty($selectable_push_flows)) {
        if (isset($entity)) {
          _cms_content_sync_add_push_pool_form($element['subform'], $selectable_push_flows, $entity);
        }
        else {
          _cms_content_sync_add_push_pool_form($element['subform'], $selectable_push_flows, NULL, $parent);
        }
      }
    }
  }
}