processDefaultValue example

public function getDefaultValue(FieldableEntityInterface $entity) {
    // Allow custom default values function.     if ($callback = $this->getDefaultValueCallback()) {
      $value = call_user_func($callback$entity$this);
    }
    else {
      $value = $this->getDefaultValueLiteral();
    }
    $value = $this->normalizeValue($value$this->getFieldStorageDefinition()->getMainPropertyName());
    // Allow the field type to process default values.     $field_item_list_class = $this->getClass();
    return $field_item_list_class::processDefaultValue($value$entity$this);
  }

  /** * Sets whether the field is translatable. * * @param bool $translatable * Whether the field is translatable. * * @return $this */
  public function setTranslatable($translatable) {
    
public function getDefaultValue(FieldableEntityInterface $entity) {
    // Allow custom default values function.     if ($callback = $this->getDefaultValueCallback()) {
      $value = call_user_func($callback$entity$this);
      $value = $this->normalizeValue($value$this->getFieldStorageDefinition()->getMainPropertyName());
    }
    else {
      $value = $this->getDefaultValueLiteral();
    }
    // Allow the field type to process default values.     $field_item_list_class = $this->getClass();
    return $field_item_list_class::processDefaultValue($value$entity$this);
  }

  /** * {@inheritdoc} */
  public function getDefaultValueLiteral() {
    return $this->default_value;
  }

  /** * {@inheritdoc} */
$form_state->setValueForElement($element['default_date']static::DEFAULT_VALUE_NOW);
      }
      return [$form_state->getValue('default_value_input')];
    }
    return [];
  }

  /** * {@inheritdoc} */
  public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
    $default_value = parent::processDefaultValue($default_value$entity$definition);

    if (isset($default_value[0]['default_date_type'])) {
      if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
        // A default date only value should be in the format used for date         // storage but in the user's local timezone.         $date = new DrupalDateTime($default_value[0]['default_date']date_default_timezone_get());
        $format = DateTimeItemInterface::DATE_STORAGE_FORMAT;
      }
      else {
        // A default date+time value should be in the format and timezone used         // for date storage.
// Ensure the returned array is ordered by deltas.       ksort($target_entities);
    }

    return $target_entities;
  }

  /** * {@inheritdoc} */
  public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
    $default_value = parent::processDefaultValue($default_value$entity$definition);

    if ($default_value) {
      // Convert UUIDs to numeric IDs.       $uuids = [];
      foreach ($default_value as $delta => $properties) {
        if (isset($properties['target_uuid'])) {
          $uuids[$delta] = $properties['target_uuid'];
        }
      }
      if ($uuids) {
        $target_type = $definition->getSetting('target_type');
        
return [$form_state->getValue('default_value_input')];
    }
    return [];
  }

  /** * {@inheritdoc} */
  public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
    // Explicitly call the base class so that we can get the default value     // types.     $default_value = FieldItemList::processDefaultValue($default_value$entity$definition);

    // Allow either the start or end date to have a default, but not require     // defaults for both.     if (!empty($default_value[0]['default_date_type']) || !empty($default_value[0]['default_end_date_type'])) {
      // A default value should be in the format and timezone used for date       // storage. All-day ranges are stored the same as date+time ranges. We       // only provide a default value for the first item, as do all fields.       // Otherwise, there is no way to clear out unwanted values on multiple       // value fields.       $storage_format = $definition->getSetting('datetime_type') == DateRangeItem::DATETIME_TYPE_DATE ? DateTimeItemInterface::DATE_STORAGE_FORMAT : DateTimeItemInterface::DATETIME_STORAGE_FORMAT;
      $default_values = [[]];

      
public function getDefaultValue(FieldableEntityInterface $entity) {
    // Allow custom default values function.     if ($callback = $this->getDefaultValueCallback()) {
      $value = call_user_func($callback$entity$this);
    }
    else {
      $value = $this->getDefaultValueLiteral();
    }
    $value = $this->normalizeValue($value$this->getMainPropertyName());
    // Allow the field type to process default values.     $field_item_list_class = $this->getClass();
    return $field_item_list_class::processDefaultValue($value$entity$this);
  }

  /** * {@inheritdoc} */
  public function setDefaultValue($value) {
    if ($value === NULL) {
      $value = [];
    }
    // Unless the value is an empty array, we may need to transform it.     if (!is_array($value) || !empty($value)) {
      
Home | Imprint | This part of the site doesn't use cookies.