You are here

public static function FileMetadataCaching::valueCallback in File metadata manager 8.2

Same name and namespace in other branches
  1. 8 src/Element/FileMetadataCaching.php \Drupal\file_mdm\Element\FileMetadataCaching::valueCallback()

Determines how user input is mapped to an element's #value property.

Parameters

array $element: An associative array containing the properties of the element.

mixed $input: The incoming input to populate the form element. If this is FALSE, the element's default value should be returned.

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

Return value

mixed The value to assign to the element.

Overrides FormElement::valueCallback

File

src/Element/FileMetadataCaching.php, line 30

Class

FileMetadataCaching
Implements a form element to enable capturing cache information for file_mdm.

Namespace

Drupal\file_mdm\Element

Code

public static function valueCallback(&$element, $input, FormStateInterface $form_state) {
  if ($input !== FALSE && $input !== NULL) {
    $disallowed_paths = $input['disallowed_paths'];
    if (!empty($disallowed_paths)) {
      $disallowed_paths = preg_replace('/\\r/', '', $disallowed_paths);
      $disallowed_paths = explode("\n", $disallowed_paths);
      while (empty($disallowed_paths[count($disallowed_paths) - 1])) {
        array_pop($disallowed_paths);
      }
      $input['disallowed_paths'] = $disallowed_paths ?: [];
    }
    else {
      $input['disallowed_paths'] = [];
    }
    return $input;
  }
  return NULL;
}