BlockForm::submitVisibility

protected BlockForm::submitVisibility(array $form, FormStateInterface $form_state)

Helper function to independently submit the visibility UI.

Parameters

array $form: A nested array form elements comprising the form.

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

File

core/modules/block/src/BlockForm.php, line 377

Class

BlockForm
Provides form for block instance forms.

Namespace

Drupal\block

Code

protected function submitVisibility(array $form, FormStateInterface $form_state) {
  foreach ($form_state->getValue('visibility') as $condition_id => $values) {
    // Allow the condition to submit the form.
    $condition = $form_state->get(['conditions', $condition_id]);
    $condition->submitConfigurationForm($form['visibility'][$condition_id], SubformState::createForSubform($form['visibility'][$condition_id], $form, $form_state));

    // Setting conditions' context mappings is the plugins' responsibility.
    // This code exists for backwards compatibility, because
    // \Drupal\Core\Condition\ConditionPluginBase::submitConfigurationForm()
    // did not set its own mappings until Drupal 8.2
    // @todo Remove the code that sets context mappings in Drupal 9.0.0.
    if ($condition instanceof ContextAwarePluginInterface) {
      $context_mapping = isset($values['context_mapping']) ? $values['context_mapping'] : [];
      $condition->setContextMapping($context_mapping);
    }

    $condition_configuration = $condition->getConfiguration();
    // Update the visibility conditions on the block.
    $this->entity->getVisibilityConditions()->addInstanceId($condition_id, $condition_configuration);
  }
}
doc_Drupal
2016-10-29 08:47:32
Comments
Leave a Comment

Please login to continue.