Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Length' => array('max' => Email::EMAIL_MAX_LENGTH, 'maxMessage' => t('%name: the email address can not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => Email::EMAIL_MAX_LENGTH))))));
     return $constraints;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $constraints[] = $manager->create('ComplexData', ['amount' => ['Regex' => ['pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i']]]);
     return $constraints;
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('TestField' => array('value' => -1, 'message' => t('%name does not accept the value @value.', array('%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1))))));
     return $constraints;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraints = parent::getConstraints();
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints[] = $constraint_manager->create('ComplexData', array('name' => array('Length' => array('max' => 64, 'maxMessage' => t('%name: may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => 64))))));
     return $constraints;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Length' => array('max' => static::COUNTRY_ISO2_MAXLENGTH, 'maxMessage' => t('%name: the country iso-2 code may not be longer than @max characters.', array('%name' => $this->getFieldDefinition()->getLabel(), '@max' => static::COUNTRY_ISO2_MAXLENGTH))))));
     return $constraints;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name)
 {
     parent::onChange($property_name);
     // Enforce that the computed date is recalculated.
     if ($property_name == 'value') {
         $this->date = NULL;
     }
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function fieldSettingsForm(array $form, FormStateInterface $form_state)
 {
     $element = parent::fieldSettingsForm($form, $form_state);
     $range = $this->getSetting('range');
     $element['range'] = array('#type' => 'textfield', '#title' => t('Range'), '#description' => t('The range of weights available to select. For
     example, a range of 20 will allow you to select a weight between -20
     and 20.'), '#default_value' => $range, '#size' => 5);
     return $element;
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     if (empty($values['data'])) {
         $values['data'] = NULL;
     } else {
         $deserialized_data = unserialize((string) $values['data']);
         $values['data'] = is_array($deserialized_data) ? $deserialized_data : NULL;
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Unserialize the values.
     // @todo The storage controller should take care of this, see
     //   SqlContentEntityStorage::loadFieldItems, see
     //   https://www.drupal.org/node/2414835
     if (isset($values['query']) && is_string($values['query'])) {
         $values['query'] = unserialize($values['query']);
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name, $notify = TRUE)
 {
     // Unset processed properties that are affected by the change.
     foreach ($this->definition->getPropertyDefinitions() as $property => $definition) {
         if ($definition->getClass() == '\\Drupal\\text\\TextProcessed') {
             if ($property_name == 'format' || $definition->getSetting('text source') == $property_name) {
                 $this->writePropertyValue($property, NULL);
             }
         }
     }
     parent::onChange($property_name, $notify);
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the first property, if no array is
     // given.
     if (is_string($values)) {
         $values = unserialize($values);
         if (!is_array($values)) {
             $values = array();
         }
     }
     $values = array('value' => $values);
     parent::setValue($values, $notify);
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $settings = $this->getSettings();
     $label = $this->getFieldDefinition()->getLabel();
     if (!empty($settings['min'])) {
         $min = $settings['min'];
         $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Range' => array('min' => $min, 'minMessage' => t('%name: the value may be no less than %min.', array('%name' => $label, '%min' => $min))))));
     }
     if (!empty($settings['max'])) {
         $max = $settings['max'];
         $constraints[] = $constraint_manager->create('ComplexData', array('value' => array('Range' => array('max' => $max, 'maxMessage' => t('%name: the value may be no greater than %max.', array('%name' => $label, '%max' => $max))))));
     }
     return $constraints;
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function preSave()
 {
     parent::preSave();
     // Merge field defaults on top of global ones.
     $default_tags = metatag_get_default_tags();
     // Get the value about to be saved.
     $current_value = $this->value;
     $current_tags = unserialize($current_value);
     // Only include values that differ from the default.
     // @TODO: When site defaults are added, account for those.
     $tags_to_save = [];
     foreach ($current_tags as $tag_id => $tag_value) {
         if (!isset($default_tags[$tag_id]) || $tag_value != $default_tags[$tag_id]) {
             $tags_to_save[$tag_id] = $tag_value;
         }
     }
     // Update the value to only save overridden tags.
     $this->value = serialize($tags_to_save);
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function preSave()
 {
     parent::preSave();
     // Get the field's default values.
     $field_default_tags_value = $this->getFieldDefaults();
     $field_default_tags = unserialize($field_default_tags_value[0]['value']);
     // Get the value about to be saved.
     $current_value = $this->value;
     $current_tags = unserialize($current_value);
     // Only include values that differ from the default.
     // @TODO: When site defaults are added, account for those.
     $tags_to_save = array();
     foreach ($current_tags as $tag_id => $tag_value) {
         if ($tag_value != $field_default_tags[$tag_id]) {
             $tags_to_save[$tag_id] = $tag_value;
         }
     }
     // Update the value to only save overridden tags.
     $this->value = serialize($tags_to_save);
 }
Ejemplo n.º 15
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraint_manager = \Drupal::typedDataManager()->getValidationConstraintManager();
     $constraints = parent::getConstraints();
     $settings = $this->getSettings();
     $label = $this->getFieldDefinition()->getLabel();
     if (!empty($settings['opacity'])) {
         $min = 0;
         $constraints[] = $constraint_manager->create('ComplexData', array('opacity' => array('Range' => array('min' => $min, 'minMessage' => t('%name: the opacity may be no less than %min.', array('%name' => $label, '%min' => $min))))));
         $max = 1;
         $constraints[] = $constraint_manager->create('ComplexData', array('opacity' => array('Range' => array('max' => $max, 'maxMessage' => t('%name: the opacity may be no greater than %max.', array('%name' => $label, '%max' => $max))))));
     }
     // @todo: Adapt constraint based on storage.
     //$constraints[] = $constraint_manager->create('ComplexData', array(
     //  'color' => array(
     //    'Regex' => array(
     //      'pattern' => '/^#(\d+)$/i',
     //    )
     //  ),
     //));
     return $constraints;
 }
Ejemplo n.º 16
0
 public function delete()
 {
     $field_collection_item = $this->getFieldCollectionItem();
     // Set a flag to remember that the host entity is being deleted. See
     // \Drupal\field_collection\Entity\FieldCollectionItem::deleteHostEntityReference().
     if ($field_collection_item !== NULL) {
         $field_collection_item->field_collection_deleting = TRUE;
         $field_collection_item->delete();
     }
     parent::delete();
 }
 /**
  * {@inheritdoc}
  */
 function __construct($definition, $name = NULL, TraversableTypedDataInterface $parent = NULL, $provider_manager)
 {
     parent::__construct($definition, $name, $parent);
     $this->providerManager = $provider_manager;
 }
Ejemplo n.º 18
0
 /**
  * {@inheritdoc}
  */
 public static function defaultStorageSettings()
 {
     return array('foreign_key_name' => 'shape') + parent::defaultStorageSettings();
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function preSave()
 {
     parent::preSave();
     $choices = $this->value;
     mailchimp_lists_process_subscribe_form_choices($choices, $this, $this->getEntity());
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name, $notify = TRUE)
 {
     // Make sure that the value and the language property stay in sync.
     if ($property_name == 'value') {
         $this->writePropertyValue('language', $this->value);
     } elseif ($property_name == 'language') {
         $this->writePropertyValue('value', $this->get('language')->getTargetIdentifier());
     }
     parent::onChange($property_name, $notify);
 }
Ejemplo n.º 21
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name)
 {
     // Make sure that the value and the language property stay in sync.
     if ($property_name == 'value') {
         $this->properties['language']->setValue($this->value, FALSE);
     } elseif ($property_name == 'language') {
         $this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE);
     }
     parent::onChange($property_name);
 }
Ejemplo n.º 22
0
 /**
  * Overrides \Drupal\Core\TypedData\FieldItemBase::setValue().
  *
  * @param array|null $values
  *   An array of property values.
  */
 public function setValue($values, $notify = TRUE)
 {
     parent::setValue($values);
     $this->populateComputedValues();
 }
Ejemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function getConstraints()
 {
     $constraints = parent::getConstraints();
     return $constraints;
 }
Ejemplo n.º 24
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name, $notify = TRUE)
 {
     // Make sure that the target ID and the target property stay in sync.
     if ($property_name == 'entity') {
         $property = $this->get('entity');
         $target_id = $property->isTargetNew() ? static::$NEW_ENTITY_MARKER : $property->getTargetIdentifier();
         $this->writePropertyValue('target_id', $target_id);
     } elseif ($property_name == 'target_id' && $this->target_id != static::$NEW_ENTITY_MARKER) {
         $this->writePropertyValue('entity', $this->target_id);
     }
     parent::onChange($property_name, $notify);
 }
Ejemplo n.º 25
0
 /**
  * {@inheritdoc}
  */
 public function onChange($property_name, $notify = TRUE)
 {
     // Enforce that the computed date is recalculated.
     if ($property_name == 'value') {
         $this->date = NULL;
     }
     parent::onChange($property_name, $notify);
 }
Ejemplo n.º 26
0
 /**
  * {@inheritdoc}
  */
 public static function defaultSettings()
 {
     return array('allowed_values' => array(), 'allowed_values_function' => '') + parent::defaultSettings();
 }
Ejemplo n.º 27
0
 /**
  * {@inheritdoc}
  */
 public static function defaultSettings()
 {
     return array('on_label' => t('On'), 'off_label' => t('Off')) + parent::defaultSettings();
 }
 /**
  * {@inheritdoc}
  */
 public function __isset($name)
 {
     // All properties depend on the main property.
     return parent::__isset($this->mainPropertyName());
 }
Ejemplo n.º 29
0
 /**
  * {@inheritdoc}
  */
 public function setValue($values, $notify = TRUE)
 {
     // Treat the values as property value of the main property, if no array is
     // given.
     if (isset($values) && !is_array($values)) {
         $values = [static::mainPropertyName() => $values];
     }
     if (isset($values)) {
         $values += ['options' => []];
     }
     // Unserialize the values.
     // @todo The storage controller should take care of this, see
     //   SqlContentEntityStorage::loadFieldItems, see
     //   https://www.drupal.org/node/2414835
     if (is_string($values['options'])) {
         $values['options'] = unserialize($values['options']);
     }
     parent::setValue($values, $notify);
 }
Ejemplo n.º 30
0
 public function delete()
 {
     $field_collection_item = $this->getFieldCollectionItem();
     if ($field_collection_item !== NULL) {
         $field_collection_item->delete();
     }
     parent::delete();
 }