You are here

public function PageExposure::configurationFormSubmit in Flexiform 8

The configuration form submit callback.

Parameters

array $form: The form array.

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

Overrides ConfigurableFormEnhancerBase::configurationFormSubmit

File

src/Plugin/FormEnhancer/PageExposure.php, line 118

Class

PageExposure
Plugin for exposing custom form modes on pages.

Namespace

Drupal\flexiform\Plugin\FormEnhancer

Code

public function configurationFormSubmit(array $form, FormStateInterface $form_state) {
  $form_mode = $form_state
    ->get('entity_form_mode');
  $values = $form_state
    ->getValue($form['#parents']);
  $settings = [];
  $settings['path'] = $values['path'];
  $settings['title'] = $values['title'];
  $settings['parameters'] = [];
  $form_display = $this
    ->getFormDisplay();
  if (preg_match_all('/{(?P<namespace>[A-Za-z0-9_]+)}/', $settings['path'], $matches)) {
    foreach ($matches['namespace'] as $namespace) {
      if ($form_entity = $form_display
        ->getFormEntityManager()
        ->getFormEntity($namespace == 'base_entity' ? $form_display
        ->getBaseEntityNamespace() : $namespace)) {
        $settings['parameters'][$namespace] = [
          'entity_type' => $form_entity
            ->getEntityType(),
          'bundle' => $form_entity
            ->getBundle(),
        ];
      }
    }
  }
  $form_mode
    ->setThirdPartySetting('flexiform', 'exposure', $settings);
  $form_mode
    ->save();
}