function FileUploadForm::hideExtraSourceFieldComponents

Same name in other branches
  1. 8.9.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::hideExtraSourceFieldComponents()
  2. 10 core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::hideExtraSourceFieldComponents()
  3. 11.x core/modules/media_library/src/Form/FileUploadForm.php \Drupal\media_library\Form\FileUploadForm::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.

$form: The complete form.

Return value

array The processed form element.

File

core/modules/media_library/src/Form/FileUploadForm.php, line 284

Class

FileUploadForm
Creates a form to create media entities from uploaded files.

Namespace

Drupal\media_library\Form

Code

public static function hideExtraSourceFieldComponents($element, FormStateInterface $form_state, $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.