本文整理汇总了PHP中Drupal\Core\Field\FieldItemBase类的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemBase类的具体用法?PHP FieldItemBase怎么用?PHP FieldItemBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FieldItemBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConstraints
/**
* {@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;
}
示例2: getConstraints
/**
* {@inheritdoc}
*/
public function getConstraints()
{
$manager = \Drupal::typedDataManager()->getValidationConstraintManager();
$constraints = parent::getConstraints();
$constraints[] = $manager->create('ComplexData', ['amount' => ['Regex' => ['pattern' => '/^[+-]?((\\d+(\\.\\d*)?)|(\\.\\d+))$/i']]]);
return $constraints;
}
示例3: getConstraints
/**
* {@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;
}
示例4: getConstraints
/**
* {@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;
}
示例5: getConstraints
/**
* {@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;
}
示例6: onChange
/**
* {@inheritdoc}
*/
public function onChange($property_name)
{
parent::onChange($property_name);
// Enforce that the computed date is recalculated.
if ($property_name == 'value') {
$this->date = NULL;
}
}
示例7: fieldSettingsForm
/**
* {@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;
}
示例8: setValue
/**
* {@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);
}
示例9: setValue
/**
* {@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);
}
示例10: onChange
/**
* {@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);
}
示例11: setValue
/**
* {@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);
}
示例12: getConstraints
/**
* {@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;
}
示例13: preSave
/**
* {@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);
}
示例14: preSave
/**
* {@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);
}
示例15: getConstraints
/**
* {@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;
}