You are here

function _cms_content_sync_override_entity_submit in CMS Content Sync 2.1.x

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

Entity status update.

Update the EntityStatus for the given entity, setting the EntityStatus::FLAG_EDIT_OVERRIDE flag accordingly.

Parameters

array $form:

\Drupal\Core\Form\FormStateInterface $form_state:

1 string reference to '_cms_content_sync_override_entity_submit'
_cms_content_sync_form_alter_disabled_fields in ./cms_content_sync.module
Disable all form elements if the content has been pulled and the user should not be able to alter pulled content.

File

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

Code

function _cms_content_sync_override_entity_submit(array $form, FormStateInterface $form_state) {
  $value = boolval($form_state
    ->getValue('cms_content_sync_edit_override'));

  /**
   * @var \Drupal\Core\Entity\EntityInterface $entity
   */
  $entity = $form_state
    ->getFormObject()
    ->getEntity();
  $entity_status = EntityStatus::getInfosForEntity($entity
    ->getEntityTypeId(), $entity
    ->uuid());
  foreach ($entity_status as $info) {
    if (!$info || !$info
      ->getLastPull() || !$info
      ->getFlow()) {
      continue;
    }
    $config = $info
      ->getFlow()
      ->getController()
      ->getEntityTypeConfig($entity
      ->getEntityTypeId(), $entity
      ->bundle());
    if ($config['import_updates'] == PullIntent::PULL_UPDATE_FORCE_UNLESS_OVERRIDDEN) {
      if ($value != $info
        ->isOverriddenLocally()) {
        $info
          ->isOverriddenLocally($value);
        $info
          ->save();
        if (!$value) {
          _cms_content_sync_reset_entity($entity, $info);
        }
      }
      break;
    }
  }
}