You are here

function menu_firstchild_menu_link_content_form_validate in Menu Firstchild 2.x

Form Validate callback.

1 string reference to 'menu_firstchild_menu_link_content_form_validate'
menu_firstchild_form_menu_link_content_form_alter in ./menu_firstchild.module
Implements hook_form_BASE_FORM_ID_alter().

File

./menu_firstchild.module, line 94
Contains menu_firstchild.module.

Code

function menu_firstchild_menu_link_content_form_validate($form, FormStateInterface $form_state) {
  $og_link_obj = $form_state
    ->getFormObject()
    ->getEntity();
  $form_storage = $form_state
    ->getStorage();
  if ($og_link_obj
    ->isDefaultTranslationAffectedOnly() && $form_storage['entity_default_langcode'] != $form_storage['langcode']) {
    $og_options = $og_link_obj->link
      ->first()->options;
    $options_to_merge = [
      'menu_firstchild' => [
        'enabled' => $og_options['menu_firstchild']['enabled'],
      ],
    ];
  }
  else {
    $options_to_merge = [
      'menu_firstchild' => [
        'enabled' => $form_state
          ->getValue('menu_firstchild_enabled'),
      ],
    ];
  }

  // Build out link array.
  $link = $form_state
    ->getValue('link');
  if (!isset($link[0]['options'])) {
    $link[0]['options'] = [];
  }
  $link[0]['options'] = array_merge($link[0]['options'], $options_to_merge);
  $form_state
    ->setValue('link', $link);
  $form_state
    ->setTemporaryValue('entity_validated', TRUE);
}