Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function settingsForm(array $form, FormStateInterface $form_state)
 {
     $elements = parent::settingsForm($form, $form_state);
     $field_name = $this->fieldDefinition->getName();
     $elements['format'] = array('#type' => 'select', '#title' => t('Name format'), '#default_value' => $this->getSetting('format'), '#options' => name_get_custom_format_options(), '#required' => TRUE);
     $elements['markup'] = array('#type' => 'checkbox', '#title' => t('Markup'), '#default_value' => $this->getSetting('markup'), '#description' => t('This option wraps the individual components of the name in SPAN elements with corresponding classes to the component.'));
     $elements['output'] = array('#type' => 'radios', '#title' => t('Output'), '#default_value' => $this->getSetting('output'), '#options' => _name_formatter_output_options(), '#description' => t('This option provides additional options for rendering the field. <strong>Normally, using the "Raw value" option would be a security risk.</strong>'), '#required' => TRUE);
     $elements['multiple'] = array('#type' => 'radios', '#title' => t('Multiple format options'), '#default_value' => $this->getSetting('multiple'), '#options' => _name_formatter_multiple_options(), '#required' => TRUE);
     $base = array('#states' => array('visible' => array(':input[name="fields[' . $field_name . '][settings_edit_form][settings][multiple]"]' => array('value' => 'inline_list'))), '#prefix' => '<div style="padding: 0 2em;">', '#suffix' => '</div>');
     // We can not nest this field, so use a prefix / suffix with padding to help
     // to provide context.
     $elements['multiple_delimiter'] = $base + array('#type' => 'textfield', '#title' => t('Delimiter'), '#default_value' => $this->getSetting('multiple_delimiter'), '#description' => t('This specifies the delimiter between the second to last and the last name.'));
     $elements['multiple_and'] = $base + array('#type' => 'radios', '#title' => t('Last delimiter type'), '#options' => array('text' => t('Textual (and)'), 'symbol' => t('Ampersand (&amp;)')), '#default_value' => $this->getSetting('multiple_and'), '#description' => t('This specifies the delimiter between the second to last and the last name.'));
     $elements['multiple_delimiter_precedes_last'] = $base + array('#type' => 'radios', '#title' => t('Standard delimiter precedes last delimiter'), '#options' => array('never' => t('Never (i.e. "J. Doe and T. Williams")'), 'always' => t('Always (i.e. "J. Doe<strong>,</strong> and T. Williams")'), 'contextual' => t('Contextual (i.e. "J. Doe and T. Williams" <em>or</em> "J. Doe, S. Smith<strong>,</strong> and T. Williams")')), '#default_value' => $this->getSetting('multiple_delimiter_precedes_last'), '#description' => t('This specifies the delimiter between the second to last and the last name. Contextual means that the delimiter is only included for lists with three or more names.'));
     $options = range(1, 20);
     $options = array_combine($options, $options);
     $elements['multiple_el_al_min'] = $base + array('#type' => 'select', '#title' => t('Reduce list and append <em>el al</em>'), '#options' => array(0 => t('Never reduce')) + $options, '#default_value' => $this->getSetting('multiple_el_al_min'), '#description' => t('This specifies a limit on the number of names to display. After this limit, names are removed and the abbrivation <em>et al</em> is appended. This Latin abbrivation of <em>et alii</em> means "and others".'));
     $elements['multiple_el_al_first'] = $base + array('#type' => 'select', '#title' => t('Number of names to display when using <em>el al</em>'), '#options' => $options, '#default_value' => $this->getSetting('multiple_el_al_first'));
     return $elements;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function fieldSettingsForm(array $form, FormStateInterface $form_state)
 {
     $settings = $this->getSettings();
     $components = _name_translations();
     $element = array('size' => array(), 'title_display' => array());
     $field_options = array('select' => t('Drop-down'), 'text' => t('Text field'), 'autocomplete' => t('Autocomplete'));
     foreach ($components as $key => $title) {
         $element['field_type'][$key] = array('#type' => 'radios', '#title' => t('@title field type', array('@title' => $components['title'])), '#default_value' => $settings['field_type'][$key], '#required' => TRUE, '#options' => $field_options);
         if (!($key == 'title' || $key == 'generational')) {
             unset($element['field_type'][$key]['#options']['select']);
         }
         $element['size'][$key] = array('#type' => 'number', '#min' => 1, '#max' => 255, '#title' => t('HTML size property for @title', array('@title' => $title)), '#default_value' => $settings['size'][$key], '#required' => FALSE, '#size' => 10, '#description' => t('The maximum length of the field in characters. This must be between 1 and 255.'));
         $element['title_display'][$key] = array('#type' => 'radios', '#title' => t('Label display for @title', array('@title' => $title)), '#default_value' => $settings['title_display'][$key], '#options' => array('title' => t('above'), 'description' => t('below'), 'none' => t('hidden')), '#description' => t('This controls how the label of the component is displayed in the form.'));
         $element['inline_css'][$key] = array('#type' => 'textfield', '#title' => t('Additional inline styles for @title input element.', array('@title' => $title)), '#default_value' => $settings['inline_css'][$key], '#size' => 8);
     }
     $element['component_css'] = array('#type' => 'textfield', '#title' => t('Component separator CSS'), '#default_value' => $this->getSetting('component_css'), '#description' => t('Use this to override the default CSS used when rendering each component. Use "&lt;none&gt;" to prevent the use of inline CSS.'));
     $items = array(t('The order for Asian names is Family Middle Given Title'), t('The order for Eastern names is Title Family Given Middle'), t('The order for Western names is Title First Middle Surname'));
     $item_list = array('#theme' => 'item_list', '#items' => $items);
     $layout_description = t('<p>This controls the order of the widgets that are displayed in the form.</p>') . drupal_render($item_list) . t('<p>Note that when you select the Asian names format, the Generational field is hidden and defaults to an empty string.</p>');
     $element['component_layout'] = array('#type' => 'radios', '#title' => t('Language layout'), '#default_value' => $this->getSetting('component_layout'), '#options' => array('default' => t('Western names'), 'asian' => t('Asian names'), 'eastern' => t('Eastern names')), '#description' => $layout_description);
     $element['show_component_required_marker'] = array('#type' => 'checkbox', '#title' => t('Show component required marker'), '#default_value' => $this->getSetting('show_component_required_marker'), '#description' => t('Appends an asterisk after the component title if the component is required as part of a complete name.'));
     $element['credentials_inline'] = array('#type' => 'checkbox', '#title' => t('Show the credentials inline'), '#default_value' => $this->getSetting('credentials_inline'), '#description' => t('The default position is to show the credentials on a line by themselves. This option overrides this to render the component inline.'));
     // Add the overwrite user name option.
     if ($this->getFieldDefinition()->getTargetEntityTypeId() == 'user') {
         $preferred_field = \Drupal::config('name.settings')->get('user_preferred');
         $element['name_user_preferred'] = array('#type' => 'checkbox', '#title' => t('Use this field to override the users login name?'), '#default_value' => $preferred_field == $this->getName() ? 1 : 0);
         $element['override_format'] = array('#type' => 'select', '#title' => t('User name override format to use'), '#default_value' => $this->getSetting('override_format'), '#options' => name_get_custom_format_options());
     } else {
         // We may extend this feature to Profile2 latter.
         $element['override_format'] = array('#type' => 'value', '#value' => $this->getSetting('override_format'));
     }
     $element['#pre_render'][] = 'name_field_settings_pre_render';
     return $element;
 }