/** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { foreach ($this->getCustomLinks($form_state->getValue('custom_links')) as $i => $link_config) { $placeholders = ['@line' => ++$i, '@path' => $link_config['path'], '@priority' => isset($link_config['priority']) ? $link_config['priority'] : '']; // Checking if internal path exists. if (!\Drupal::service('path.validator')->isValid($link_config['path']) || strpos($link_config['path'], '//') !== FALSE) { // Path validator does not see a double slash as an error. Catching this to prevent breaking path generation. $form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> does not exist.", $placeholders)); } // Making sure the paths start with a slash. if ($link_config['path'][0] != '/') { $form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The path <em>@path</em> needs to start with a '/'.", $placeholders)); } // Making sure the priority is formatted correctly. if (isset($link_config['priority']) && !Form::isValidPriority($link_config['priority'])) { $form_state->setErrorByName('', $this->t("<strong>Line @line</strong>: The priority setting <em>@priority</em> for path <em>@path</em> is incorrect. Set the priority from 0.0 to 1.0.", $placeholders)); } } }
private function addLinkSettings($type, $settings, &$target) { foreach ($settings as $setting_key => $setting) { if (in_array($setting_key, self::$allowed_link_settings[$type])) { switch ($setting_key) { case 'priority': if (Form::isValidPriority($setting)) { // todo: register error continue; } break; //todo: add index check } $target[$setting_key] = $setting; } } }