You are here

public static function AddMediaFormBase::hideExtraSourceFieldComponents in Media Directories 2.x

Same name and namespace in other branches
  1. 8 modules/media_directories_ui/src/Form/AddMediaFormBase.php \Drupal\media_directories_ui\Form\AddMediaFormBase::hideExtraSourceFieldComponents()

Processes an image or file source field element.

Parameters

array $element: The entity form source field element.

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

array $form: The complete form.

Return value

array The processed form element.

File

modules/media_directories_ui/src/Form/AddMediaFormBase.php, line 580

Class

AddMediaFormBase
Class AddMediaFormBase.

Namespace

Drupal\media_directories_ui\Form

Code

public static function hideExtraSourceFieldComponents(array $element, FormStateInterface $form_state, array $form) {

  // Remove original button added by ManagedFile::processManagedFile().
  if (!empty($element['remove_button'])) {
    $element['remove_button']['#access'] = FALSE;
  }

  // Remove preview added by ImageWidget::process().
  if (!empty($element['preview'])) {
    $element['preview']['#access'] = FALSE;
  }
  $element['#title_display'] = 'none';
  $element['#description_display'] = 'none';

  // Remove the filename display.
  foreach ($element['#files'] as $file) {
    $element['file_' . $file
      ->id()]['filename']['#access'] = FALSE;
  }
  return $element;
}