Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function allowedValuesDescription()
 {
     $description = '<p>' . t('The possible values this field can contain. Enter one value per line, in the format key|label.');
     $description .= '<br/>' . t('The key is the stored value. The label will be used in displayed values and edit forms.');
     $description .= '<br/>' . t('The label is optional: if a line contains a single string, it will be used as key and label.');
     $description .= '</p>';
     $description .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '</p>';
     return $description;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function allowedValuesDescription()
 {
     $description = '<p>' . t('The possible values this field can contain. Enter one value per line, in the format key|label.');
     $description .= '<br/>' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.');
     $description .= '<br/>' . t('The label is optional: if a line contains a single number, it will be used as key and label.');
     $description .= '<br/>' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.');
     $description .= '</p>';
     $description .= '<p>' . t('Allowed HTML tags in labels: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '</p>';
     return $description;
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, FieldInstanceConfigInterface $field_instance_config = NULL)
 {
     $this->instance = $form_state['instance'] = $field_instance_config;
     $bundle = $this->instance->bundle;
     $entity_type = $this->instance->entity_type;
     $field_storage = $this->instance->getFieldStorageDefinition();
     $bundles = entity_get_bundles();
     $form_title = $this->t('%instance settings for %bundle', array('%instance' => $this->instance->getLabel(), '%bundle' => $bundles[$entity_type][$bundle]['label']));
     $form['#title'] = $form_title;
     $form['#field'] = $field_storage;
     // Create an arbitrary entity object (used by the 'default value' widget).
     $ids = (object) array('entity_type' => $this->instance->entity_type, 'bundle' => $this->instance->bundle, 'entity_id' => NULL);
     $form['#entity'] = _field_create_entity_from_ids($ids);
     $items = $form['#entity']->get($this->instance->getName());
     if (!empty($field_storage->locked)) {
         $form['locked'] = array('#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->instance->getLabel())));
         return $form;
     }
     // Create a form structure for the instance values.
     $form['instance'] = array('#tree' => TRUE);
     // Build the non-configurable instance values.
     $form['instance']['field_name'] = array('#type' => 'value', '#value' => $this->instance->getName());
     $form['instance']['entity_type'] = array('#type' => 'value', '#value' => $entity_type);
     $form['instance']['bundle'] = array('#type' => 'value', '#value' => $bundle);
     // Build the configurable instance values.
     $form['instance']['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => $this->instance->getLabel() ?: $field_storage->getName(), '#required' => TRUE, '#weight' => -20);
     $form['instance']['description'] = array('#type' => 'textarea', '#title' => $this->t('Help text'), '#default_value' => $this->instance->getDescription(), '#rows' => 5, '#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => _field_filter_xss_display_allowed_tags())) . '<br />' . $this->t('This field supports tokens.'), '#weight' => -10);
     $form['instance']['required'] = array('#type' => 'checkbox', '#title' => $this->t('Required field'), '#default_value' => $this->instance->isRequired(), '#weight' => -5);
     // Add instance settings for the field type.
     $form['instance']['settings'] = $items[0]->instanceSettingsForm($form, $form_state);
     $form['instance']['settings']['#weight'] = 10;
     // Add handling for default value.
     if ($element = $items->defaultValuesForm($form, $form_state)) {
         $element += array('#type' => 'details', '#title' => $this->t('Default value'), '#open' => TRUE, '#description' => $this->t('The default value for this field, used when creating new content.'));
         $form['instance']['default_value'] = $element;
     }
     $form['actions'] = array('#type' => 'actions');
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save settings'));
     $form['actions']['delete'] = array('#type' => 'submit', '#value' => $this->t('Delete field'), '#submit' => array(array($this, 'delete')));
     return $form;
 }