FieldStorageDefinitionUpdateForbiddenException example


function hook_field_storage_config_update_forbid(\Drupal\field\FieldStorageConfigInterface $field_storage, \Drupal\field\FieldStorageConfigInterface $prior_field_storage) {
  if ($field_storage->getTypeProvider() == 'options' && $field_storage->hasData()) {
    // Forbid any update that removes allowed values with actual data.     $allowed_values = $field_storage->getSetting('allowed_values');
    $prior_allowed_values = $prior_field_storage->getSetting('allowed_values');
    $lost_keys = array_keys(array_diff_key($prior_allowed_values$allowed_values));
    if (_options_values_in_use($field_storage->getTargetEntityTypeId()$field_storage->getName()$lost_keys)) {
      throw new \Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException("A list field '{$field_storage->getName()}' with existing data cannot have its keys changed.");
    }
  }
}

/** * @} End of "defgroup field_types". */

/** * @defgroup field_widget Field Widget API * @{ * Define Field API widget types. * * Field API widgets specify how fields are displayed in edit forms. Fields of a * given @link field_types field type @endlink may be edited using more than one * widget. In this case, the Field UI module allows the site builder to choose * which widget to use. * * Widgets are Plugins managed by the * \Drupal\Core\Field\WidgetPluginManager class. A widget is a plugin annotated * with class \Drupal\Core\Field\Annotation\FieldWidget that implements * \Drupal\Core\Field\WidgetInterface (in most cases, by * subclassing \Drupal\Core\Field\WidgetBase). Widget plugins need to be in the * namespace \Drupal\{your_module}\Plugin\Field\FieldWidget. * * Widgets are @link form_api Form API @endlink elements with additional * processing capabilities. The methods of the WidgetInterface object are * typically called by respective methods in the * \Drupal\Core\Entity\Entity\EntityFormDisplay class. * * @see field * @see field_types * @see field_formatter * @see plugin_api */

        }
        else {
          // Recreate tables.           $this->performFieldSchemaOperation('create', $original);
        }
        throw $e;
      }
    }
    else {
      if ($this->hasColumnChanges($storage_definition$original)) {
        throw new FieldStorageDefinitionUpdateForbiddenException('The SQL storage cannot change the schema for an existing field (' . $storage_definition->getName() . ' in ' . $storage_definition->getTargetEntityTypeId() . ' entity) with data.');
      }
      // There is data, so there are no column changes. Drop all the prior       // indexes and create all the new ones, except for all the priors that       // exist unchanged.       $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]);
      $table = $table_mapping->getDedicatedDataTableName($original);
      $revision_table = $table_mapping->getDedicatedRevisionTableName($original);

      // Get the field schemas.       $schema = $storage_definition->getSchema();
      $original_schema = $original->getSchema();

      
Home | Imprint | This part of the site doesn't use cookies.