Exemple #1
0
/**
 * Allow modules to add settings to field widgets provided by other modules.
 *
 * @param \Drupal\Core\Field\WidgetInterface $plugin
 *   The instantiated field widget plugin.
 * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
 *   The field definition.
 * @param $form_mode
 *   The entity form mode.
 * @param array $form
 *   The (entire) configuration form array.
 * @param array $form_state
 *   The form state.
 *
 * @return array
 *   Returns the form array to be built.
 *
 * @see \Drupal\field_ui\FormDisplayOverView.
 */
function hook_field_widget_third_party_settings_form(\Drupal\Core\Field\WidgetInterface $plugin, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, $form_mode, $form, $form_state)
{
    $element = array();
    // Add a 'my_setting' checkbox to the settings form for 'foo_widget' field
    // widgets.
    if ($plugin->getPluginId() == 'foo_widget') {
        $element['my_setting'] = array('#type' => 'checkbox', '#title' => t('My setting'), '#default_value' => $plugin->getThirdPartySetting('my_module', 'my_setting'));
    }
    return $element;
}
 /**
  * Checks if a widget is supported.
  */
 public static function isWidgetSupported(WidgetInterface $widget)
 {
     return in_array($widget->getPluginId(), static::supportedWidgets());
 }
 /**
  * Implements hook_filefield_source_settings().
  */
 public static function settings(WidgetInterface $plugin)
 {
     $settings = $plugin->getThirdPartySetting('filefield_sources', 'filefield_sources', array('source_reference' => array('autocomplete' => FILEFIELD_SOURCE_REFERENCE_STARTS_WITH_AUTOCOMPLETE_TYPE)));
     $return['source_reference'] = array('#title' => t('Autocomplete reference options'), '#type' => 'details');
     $return['source_reference']['autocomplete'] = array('#title' => t('Match file name'), '#options' => array(FILEFIELD_SOURCE_REFERENCE_STARTS_WITH_AUTOCOMPLETE_TYPE => t('Starts with'), FILEFIELD_SOURCE_REFERENCE_CONTAINS_AUTOCOMPLETE_TYPE => t('Contains')), '#type' => 'radios', '#default_value' => isset($settings['source_reference']['autocomplete']) ? $settings['source_reference']['autocomplete'] : FILEFIELD_SOURCE_REFERENCE_STARTS_WITH_AUTOCOMPLETE_TYPE);
     return $return;
 }
 /**
  * Implements hook_filefield_source_settings().
  */
 public static function settings(WidgetInterface $plugin)
 {
     $settings = $plugin->getThirdPartySetting('filefield_sources', 'filefield_sources', array('source_attach' => array('path' => FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH, 'absolute' => FILEFIELD_SOURCE_ATTACH_RELATIVE, 'attach_mode' => FILEFIELD_SOURCE_ATTACH_MODE_MOVE)));
     $return['source_attach'] = array('#title' => t('File attach settings'), '#type' => 'details', '#description' => t('File attach allows for selecting a file from a directory on the server, commonly used in combination with FTP.') . ' <strong>' . t('This file source will ignore file size checking when used.') . '</strong>', '#element_validate' => array(array(get_called_class(), 'filePathValidate')), '#weight' => 3);
     $return['source_attach']['path'] = array('#type' => 'textfield', '#title' => t('File attach path'), '#default_value' => $settings['source_attach']['path'], '#size' => 60, '#maxlength' => 128, '#description' => t('The directory within the <em>File attach location</em> that will contain attachable files.'));
     if (\Drupal::moduleHandler()->moduleExists('token')) {
         $return['source_attach']['tokens'] = array('#theme' => 'token_tree', '#token_types' => array('user'));
     }
     $return['source_attach']['absolute'] = array('#type' => 'radios', '#title' => t('File attach location'), '#options' => array(FILEFIELD_SOURCE_ATTACH_RELATIVE => t('Within the files directory'), FILEFIELD_SOURCE_ATTACH_ABSOLUTE => t('Absolute server path')), '#default_value' => $settings['source_attach']['absolute'], '#description' => t('The <em>File attach path</em> may be with the files directory (%file_directory) or from the root of your server. If an absolute path is used and it does not start with a "/" your path will be relative to your site directory: %realpath.', array('%file_directory' => drupal_realpath(file_default_scheme() . '://'), '%realpath' => realpath('./'))));
     $return['source_attach']['attach_mode'] = array('#type' => 'radios', '#title' => t('Attach method'), '#options' => array(FILEFIELD_SOURCE_ATTACH_MODE_MOVE => t('Move the file directly to the final location'), FILEFIELD_SOURCE_ATTACH_MODE_COPY => t('Leave a copy of the file in the attach directory')), '#default_value' => isset($settings['source_attach']['attach_mode']) ? $settings['source_attach']['attach_mode'] : 'move');
     return $return;
 }
 /**
  * Implements hook_filefield_source_settings().
  */
 public static function settings(WidgetInterface $plugin)
 {
     $scheme_settings = Settings::get('flysystem', []);
     $flysystem_array = [];
     foreach ($scheme_settings as $key => $value) {
         $flysystem_array[$key] = ucfirst($value['driver']);
     }
     $settings = $plugin->getThirdPartySetting('filefield_sources', 'filefield_sources', array('flysystem' => array('path' => FILEFIELD_SOURCE_FLYSYSTEM_ATTACH_DEFAULT_PATH, 'attach_mode' => FILEFIELD_SOURCE_FLYSYSTEM_ATTACH_MODE_MOVE, 'select_scheme' => FILEFIELD_SOURCE_FLYSYSTEM_SCHEME)));
     $return['flysystem'] = array('#title' => t('Flysystem settings'), '#type' => 'details', '#description' => t('Select files from a filesystem by Flysystem.'), '#weight' => 3);
     $return['flysystem']['select_scheme'] = array('#type' => 'radios', '#title' => t('Flysystem filesystems'), '#options' => $flysystem_array, '#default_value' => isset($settings['flysystem']['select_scheme']) ? $settings['flysystem']['select_scheme'] : '');
     $return['flysystem']['path'] = array('#type' => 'textfield', '#title' => t('Filesystem path'), '#default_value' => $settings['flysystem']['path'], '#size' => 60, '#maxlength' => 128, '#description' => t('The directory within the Flysystem filesystem that will contain attachable files.'));
     if (\Drupal::moduleHandler()->moduleExists('token')) {
         $return['flysystem']['tokens'] = array('#theme' => 'token_tree', '#token_types' => array('user'));
     }
     $return['flysystem']['attach_mode'] = array('#type' => 'radios', '#title' => t('File Options'), '#options' => array(FILEFIELD_SOURCE_FLYSYSTEM_ATTACH_MODE_MOVE => t('Move the file to the storage destination'), FILEFIELD_SOURCE_FLYSYSTEM_ATTACH_MODE_COPY => t('Copy the file to the storage destination'), FILEFIELD_SOURCE_FLYSYSTEM_ATTACH_MODE_SERVEFROMFOLDER => t('Serve the file from its current location (only possible when this Flysystem filesystem is also the file storage destination for this file field).')), '#default_value' => isset($settings['flysystem']['attach_mode']) ? $settings['flysystem']['attach_mode'] : 'move');
     return $return;
 }
Exemple #6
0
 /**
  * Implements hook_filefield_source_settings().
  */
 public static function settings(WidgetInterface $plugin)
 {
     $settings = $plugin->getThirdPartySetting('filefield_sources', 'filefield_sources', array('source_imce' => array('imce_mode' => 0)));
     $return['source_imce'] = array('#title' => t('IMCE file browser settings'), '#type' => 'details', '#access' => \Drupal::moduleHandler()->moduleExists('imce'));
     // $imce_admin_url = \Drupal::url('imce.admin');
     $imce_admin_url = 'admin/config/media/imce';
     $return['source_imce']['imce_mode'] = array('#type' => 'radios', '#title' => t('File browser mode'), '#options' => array(0 => t('Restricted: Users can only browse the field directory. No file operations are allowed.'), 1 => t('Full: Browsable directories are defined by <a href="!imce-admin-url">IMCE configuration profiles</a>. File operations are allowed.', array('!imce-admin-url' => $imce_admin_url))), '#default_value' => isset($settings['source_imce']['imce_mode']) ? $settings['source_imce']['imce_mode'] : 0);
     return $return;
 }