You are here

public static function Reference::settings in FileField Sources 8

Implements hook_filefield_source_settings().

File

src/Plugin/FilefieldSource/Reference.php, line 199

Class

Reference
A FileField source plugin to allow referencing of existing files.

Namespace

Drupal\filefield_sources\Plugin\FilefieldSource

Code

public static function settings(WidgetInterface $plugin) {
  $settings = $plugin
    ->getThirdPartySetting('filefield_sources', 'filefield_sources', [
    'source_reference' => [
      'autocomplete' => FILEFIELD_SOURCE_REFERENCE_MATCH_STARTS_WITH,
      'search_all_fields' => FILEFIELD_SOURCE_REFERENCE_SEARCH_ALL_NO,
    ],
  ]);
  $return['source_reference'] = [
    '#title' => t('Autocomplete reference options'),
    '#type' => 'details',
  ];
  $return['source_reference']['autocomplete'] = [
    '#title' => t('Match file name'),
    '#options' => [
      FILEFIELD_SOURCE_REFERENCE_MATCH_STARTS_WITH => t('Starts with'),
      FILEFIELD_SOURCE_REFERENCE_MATCH_CONTAINS => t('Contains'),
    ],
    '#type' => 'radios',
    '#default_value' => isset($settings['source_reference']['autocomplete']) ? $settings['source_reference']['autocomplete'] : FILEFIELD_SOURCE_REFERENCE_MATCH_STARTS_WITH,
  ];
  $return['source_reference']['search_all_fields'] = [
    '#title' => t('Search all file fields'),
    '#options' => [
      FILEFIELD_SOURCE_REFERENCE_SEARCH_ALL_NO => t('No (only fields with the same field base will be searched)'),
      FILEFIELD_SOURCE_REFERENCE_SEARCH_ALL_YES => t('Yes (all file fields will be searched, regardless of type)'),
    ],
    '#type' => 'radios',
    '#default_value' => isset($settings['source_reference']['search_all_fields']) ? $settings['source_reference']['search_all_fields'] : FILEFIELD_SOURCE_REFERENCE_SEARCH_ALL_NO,
  ];
  return $return;
}