Skip to content
Snippets Groups Projects
Commit 89379df0 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2201087 by plopesc: Rename hook_field_update_forbid to hook_field_config_update_forbid.

parent 28d5e269
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Uuid\Uuid;
use Drupal\field\FieldInfo;
use Drupal\field\FieldUpdateForbiddenException;
use Drupal\field\FieldConfigUpdateForbiddenException;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\Entity\FieldConfig;
......
......@@ -8,13 +8,10 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\Language\Language;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Uuid\Uuid;
use Drupal\field\FieldInfo;
use Drupal\field\FieldUpdateForbiddenException;
use Drupal\field\FieldConfigUpdateForbiddenException;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldInstanceConfigInterface;
use Drupal\field\Entity\FieldConfig;
......@@ -1011,7 +1008,7 @@ public function onFieldUpdate(FieldConfigInterface $field) {
}
else {
if ($field->getColumns() != $original->getColumns()) {
throw new FieldUpdateForbiddenException("The SQL storage cannot change the schema for an existing field with data.");
throw new FieldConfigUpdateForbiddenException("The SQL storage cannot change the schema for an existing field 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
......
......@@ -6,7 +6,7 @@
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\field\FieldUpdateForbiddenException;
use Drupal\field\FieldConfigUpdateForbiddenException;
/**
* Exposes "pseudo-field" components on fieldable entities.
......@@ -409,14 +409,14 @@ function hook_field_info_max_weight($entity_type, $bundle, $context, $context_mo
* that cannot be updated.
*
* To forbid the update from occurring, throw a
* Drupal\field\FieldUpdateForbiddenException.
* Drupal\field\FieldConfigUpdateForbiddenException.
*
* @param $field
* @param \Drupal\field\FieldConfigInterface $field
* The field as it will be post-update.
* @param $prior_field
* @param \Drupal\field\FieldConfigInterface $prior_field
* The field as it is pre-update.
*/
function hook_field_update_forbid($field, $prior_field) {
function hook_field_config_update_forbid(\Drupal\field\FieldConfigInterface $field, \Drupal\field\FieldConfigInterface $prior_field) {
// A 'list' field stores integer keys mapped to display values. If
// the new field will have fewer values, and any data exists for the
// abandoned keys, the field will have no way to display them. So,
......@@ -431,7 +431,7 @@ function hook_field_update_forbid($field, $prior_field) {
->range(0, 1)
->execute();
if ($found) {
throw new FieldUpdateForbiddenException("Cannot update a list field not to include keys with existing data");
throw new FieldConfigUpdateForbiddenException("Cannot update a list field not to include keys with existing data");
}
}
}
......
......@@ -360,8 +360,8 @@ protected function preSaveUpdated(EntityStorageControllerInterface $storage_cont
$this->settings += $field_type_manager->getDefaultSettings($this->type);
// See if any module forbids the update by throwing an exception. This
// invokes hook_field_update_forbid().
$module_handler->invokeAll('field_update_forbid', array($this, $this->original));
// invokes hook_field_config_update_forbid().
$module_handler->invokeAll('field_config_update_forbid', array($this, $this->original));
// Notify the storage controller. The controller can reject the definition
// update as invalid by raising an exception, which stops execution before
......
<?php
/**
* @file
* Contains \Drupal\field\FieldConfigUpdateForbiddenException.
*/
namespace Drupal\field;
/**
* Exception class thrown by hook_field_config_update_forbid().
*/
class FieldConfigUpdateForbiddenException extends FieldException {}
<?php
/**
* @file
* Contains \Drupal\field\FieldUpdateForbiddenException.
*/
namespace Drupal\field;
/**
* Exception class thrown by hook_field_update_forbid().
*/
class FieldUpdateForbiddenException extends FieldException {}
......@@ -9,7 +9,8 @@
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\field\FieldException;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldConfigUpdateForbiddenException;
/**
* Implements hook_field_widget_info_alter().
......@@ -19,11 +20,11 @@ function field_test_field_widget_info_alter(&$info) {
}
/**
* Implements hook_field_update_forbid().
* Implements hook_field_config_update_forbid().
*/
function field_test_field_update_forbid($field, $prior_field) {
function field_test_field_config_update_forbid(FieldConfigInterface $field, FieldConfigInterface $prior_field) {
if ($field->getType() == 'test_field' && $field->getSetting('unchangeable') != $prior_field->getSetting('unchangeable')) {
throw new FieldException("field_test 'unchangeable' setting cannot be changed'");
throw new FieldConfigUpdateForbiddenException("field_test 'unchangeable' setting cannot be changed'");
}
}
......
......@@ -9,7 +9,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\field\FieldConfigInterface;
use Drupal\field\FieldUpdateForbiddenException;
use Drupal\field\FieldConfigUpdateForbiddenException;
/**
* Implements hook_help().
......@@ -100,16 +100,16 @@ function options_allowed_values(FieldDefinitionInterface $field_definition, Enti
}
/**
* Implements hook_field_update_forbid().
* Implements hook_field_config_update_forbid().
*/
function options_field_update_forbid($field, $prior_field) {
function options_field_config_update_forbid(FieldConfigInterface $field, FieldConfigInterface $prior_field) {
if ($field->module == 'options' && $field->hasData()) {
// Forbid any update that removes allowed values with actual data.
$allowed_values = $field->getSetting('allowed_values');
$prior_allowed_values = $prior_field->getSetting('allowed_values');
$lost_keys = array_diff(array_keys($prior_allowed_values), array_keys($allowed_values));
if (_options_values_in_use($field->entity_type, $field->getName(), $lost_keys)) {
throw new FieldUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field->getName())));
throw new FieldConfigUpdateForbiddenException(t('A list field (@field_name) with existing data cannot have its keys changed.', array('@field_name' => $field->getName())));
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment