You are here

public static function BlockUploadManager::blockUploadFieldOptionsFormElements in Block Upload 8

Dynamic form elements for image/file field types.

Parameters

array $form: Form array into which need add form elements.

int $buid: Block upload variable ID.

string $type: Field type.

2 calls to BlockUploadManager::blockUploadFieldOptionsFormElements()
BlockUploadBlock::blockForm in src/Plugin/Block/BlockUploadBlock.php
BlockUploadBlock::blockUploadAjaxCallback in src/Plugin/Block/BlockUploadBlock.php
Display fields checkboxes depends on selected field.

File

src/BlockUploadManager.php, line 79

Class

BlockUploadManager
BlockUploadManager class.

Namespace

Drupal\block_upload

Code

public static function blockUploadFieldOptionsFormElements(array &$form, $buid, $type) {
  $form['config'] = [
    '#title' => t("Additional display"),
    '#description' => t('Alt and title fields display for single form display. Will not apply for plupload widget.'),
    '#prefix' => '<div id="config">',
    '#suffix' => '</div>',
    '#type' => 'fieldset',
  ];
  $settings = \Drupal::state()
    ->get('block_upload_' . $buid . '_settings') ?: [];

  // Alt and title enable options form elements for image field type.
  if ($type == 'image') {
    $form['config']['block_upload_' . $buid . '_alt'] = [
      '#type' => 'checkbox',
      '#title' => t('Show alt field'),
      '#default_value' => isset($settings['alt']) ? $settings['alt'] : 0,
    ];
    $form['config']['block_upload_' . $buid . '_title'] = [
      '#type' => 'checkbox',
      '#title' => t('Show title field'),
      '#default_value' => isset($settings['title']) ? $settings['title'] : 0,
    ];
  }
  elseif ($type == 'file') {
    $form['config']['block_upload_' . $buid . '_desc'] = [
      '#type' => 'checkbox',
      '#title' => t('Show description field'),
      '#default_value' => isset($settings['desc']) ? $settings['desc'] : 0,
    ];
  }

  // Check if plupload module exists and display enable option.
  if (\Drupal::moduleHandler()
    ->moduleExists('plupload')) {
    $form['block_upload_' . $buid . '_plupload_status'] = [
      '#type' => 'checkbox',
      '#title' => t('Use Plupoad for file uploads'),
      '#default_value' => isset($settings['plupload']) ? $settings['plupload'] : 0,
    ];
  }
  else {
    $description = t('To enable multiuploads and drag&drop upload features, download and install Plupload module');
    $form['block_upload_' . $buid . '_plupload_status'] = [
      '#type' => 'checkbox',
      '#title' => t('Use Plupoad for file uploads'),
      '#disabled' => TRUE,
      '#description' => $description,
    ];
  }
}