示例#1
0
 /**
  * {@inheritdoc}
  */
 public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data)
 {
     $element = array();
     $element['max_length'] = array('#type' => 'number', '#title' => t('Maximum length'), '#default_value' => $this->getSetting('max_length'), '#required' => TRUE, '#description' => t('The maximum length of the field in characters.'), '#min' => 1, '#disabled' => $has_data);
     $element += parent::storageSettingsForm($form, $form_state, $has_data);
     return $element;
 }
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     if ($max_length = $this->getSetting('max_length')) {
         $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Length' => array('max' => $max_length, 'maxMessage' => t('%name: the text may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length))))));
     }
     return $constraints;
 }
 /**
  * {@inheritdoc}
  */
 public function isEmpty()
 {
     $value = $this->get('summary')->getValue();
     return parent::isEmpty() && ($value === NULL || $value === '');
 }