You are here

function social_core_path_validate in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/social_core.module \social_core_path_validate()
  2. 8.2 modules/social_features/social_core/social_core.module \social_core_path_validate()
  3. 8.3 modules/social_features/social_core/social_core.module \social_core_path_validate()
  4. 8.4 modules/social_features/social_core/social_core.module \social_core_path_validate()
  5. 8.5 modules/social_features/social_core/social_core.module \social_core_path_validate()
  6. 8.6 modules/social_features/social_core/social_core.module \social_core_path_validate()
  7. 8.7 modules/social_features/social_core/social_core.module \social_core_path_validate()
  8. 8.8 modules/social_features/social_core/social_core.module \social_core_path_validate()
  9. 10.3.x modules/social_features/social_core/social_core.module \social_core_path_validate()
  10. 10.0.x modules/social_features/social_core/social_core.module \social_core_path_validate()
  11. 10.1.x modules/social_features/social_core/social_core.module \social_core_path_validate()
  12. 10.2.x modules/social_features/social_core/social_core.module \social_core_path_validate()

Form element validation handler for URL alias form element.

Parameters

array $element: The form element.

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

1 string reference to 'social_core_path_validate'
social_core_field_widget_form_alter in modules/social_features/social_core/social_core.module
Implements hook_field_widget_form_alter().

File

modules/social_features/social_core/social_core.module, line 502
The Social core module.

Code

function social_core_path_validate(array &$element, FormStateInterface $form_state) {
  $alias = trim($element['alias']['#value'], " \\/");
  $parsed_url = parse_url($alias);
  if (isset($parsed_url['host']) || isset($parsed_url['scheme']) || !isset($parsed_url['path'])) {
    $form_state
      ->setError($element, t('The URL alias must be a relative URL.'));
  }
  if (!$form_state
    ->getErrors()) {
    $element['alias']['#value'] = '/' . ltrim($element['alias']['#value'], '/');
    PathWidget::validateFormElement($element, $form_state);
  }
}