diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 2448d738adb6971456274c31ab2888c4c32e648f..44aa50b53c8dd2f7fa7ac4880ed8ffae3562e1e2 100644 --- a/core/modules/field/field.api.php +++ b/core/modules/field/field.api.php @@ -5,6 +5,8 @@ * @{ */ +use Drupal\field\FieldUpdateForbiddenException; + /** * Exposes "pseudo-field" components on fieldable entities. * @@ -2434,7 +2436,8 @@ function hook_field_create_instance($instance) { * semantics, or if there are external dependencies on field settings * that cannot be updated. * - * To forbid the update from occurring, throw a FieldUpdateForbiddenException. + * To forbid the update from occurring, throw a + * Drupal\field\FieldUpdateForbiddenException. * * @param $field * The field as it will be post-update. diff --git a/core/modules/field/field.attach.inc b/core/modules/field/field.attach.inc index ff579c7b4c6a5197aff37d9f044d89a2ad86dabb..cf597f0d9620f383f34ce789149a626f0b532d0f 100644 --- a/core/modules/field/field.attach.inc +++ b/core/modules/field/field.attach.inc @@ -5,29 +5,7 @@ * Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'. */ -/** - * Exception thrown by field_attach_validate() on field validation errors. - */ -class FieldValidationException extends FieldException { - var $errors; - - /** - * Constructor for FieldValidationException. - * - * @param $errors - * An array of field validation errors, keyed by field name and - * delta that contains two keys: - * - 'error': A machine-readable error code string, prefixed by - * the field module name. A field widget may use this code to decide - * how to report the error. - * - 'message': A human-readable error message such as to be - * passed to form_error() for the appropriate form element. - */ - function __construct($errors) { - $this->errors = $errors; - parent::__construct(t('Field validation errors')); - } -} +use Drupal\field\FieldValidationException; /** * @defgroup field_storage Field Storage API @@ -765,7 +743,7 @@ function field_attach_load_revision($entity_type, $entities, $options = array()) * The type of $entity; e.g. 'node' or 'user'. * @param $entity * The entity with fields to validate. - * @throws FieldValidationException + * @throws Drupal\field\FieldValidationException * If validation errors are found, a FieldValidationException is thrown. The * 'errors' property contains the array of errors, keyed by field name, * language and delta. diff --git a/core/modules/field/field.crud.inc b/core/modules/field/field.crud.inc index f9c96c92b020b98ab196a19d29fc8265d4776cdd..4a4842f19d09c9815e6b48f3649cbe17bdc8433a 100644 --- a/core/modules/field/field.crud.inc +++ b/core/modules/field/field.crud.inc @@ -5,6 +5,8 @@ * Field CRUD API, handling field and field instance creation and deletion. */ +use Drupal\field\FieldException; + /** * @defgroup field_crud Field CRUD API * @{ @@ -49,7 +51,7 @@ * @return * The $field array with the id property filled in. * - * @throws FieldException + * @throws Drupal\field\FieldException * * See: @link field Field API data structures @endlink. */ @@ -213,8 +215,9 @@ function field_create_field($field) { * structure. Any other properties of the field that are not * specified in $field will be left unchanged, so it is not * necessary to pass in a fully populated $field structure. - * @return - * Throws a FieldException if the update cannot be performed. + * + * @throws Drupal\field\FieldException + * * @see field_create_field() */ function field_update_field($field) { @@ -447,7 +450,7 @@ function field_delete_field($field_name) { * @return * The $instance array with the id property filled in. * - * @throws FieldException + * @throws Drupal\field\FieldException * * See: @link field Field API data structures @endlink. */ @@ -514,7 +517,7 @@ function field_create_instance($instance) { * properties specified in $instance overwrite the existing values for * the instance. * - * @throws FieldException + * @throws Drupal\field\FieldException * * @see field_create_instance() */ diff --git a/core/modules/field/field.module b/core/modules/field/field.module index eabcf2a29a0bc5c913ee6ba995b96b56009d10e0..ab67eb26316b19c537c5386603ebf77406aa4490 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -4,14 +4,6 @@ * Attach custom data fields to Drupal entities. */ -/** - * Base class for all exceptions thrown by Field API functions. - * - * This class has no functionality of its own other than allowing all - * Field API exceptions to be caught by a single catch block. - */ -class FieldException extends Exception {} - /* * Load all public Field API functions. Drupal currently has no * mechanism for auto-loading core APIs, so we have to load them on @@ -273,11 +265,6 @@ class FieldException extends Exception {} */ const FIELD_LOAD_REVISION = 'FIELD_LOAD_REVISION'; -/** - * Exception class thrown by hook_field_update_forbid(). - */ -class FieldUpdateForbiddenException extends FieldException {} - /** * Implements hook_help(). */ diff --git a/core/modules/field/lib/Drupal/field/FieldException.php b/core/modules/field/lib/Drupal/field/FieldException.php new file mode 100644 index 0000000000000000000000000000000000000000..b653109f7194157f5f2365efe525088dc25d855f --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldException.php @@ -0,0 +1,18 @@ +<?php + +/* + * @file + * Definition of Drupal\field\FieldExeption. + */ + +namespace Drupal\field; + +use RuntimeException; + +/** + * Base class for all exceptions thrown by Field API functions. + * + * This class has no functionality of its own other than allowing all + * Field API exceptions to be caught by a single catch block. + */ +class FieldException extends RuntimeException {} diff --git a/core/modules/field/lib/Drupal/field/FieldUpdateForbiddenException.php b/core/modules/field/lib/Drupal/field/FieldUpdateForbiddenException.php new file mode 100644 index 0000000000000000000000000000000000000000..6bf914f17b96287d58fa7b94e8c014b1df66a21e --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldUpdateForbiddenException.php @@ -0,0 +1,13 @@ +<?php + +/* + * @file + * Definition of Drupal\field\FieldUpdateForbiddenException. + */ + +namespace Drupal\field; + +/** + * Exception class thrown by hook_field_update_forbid(). + */ +class FieldUpdateForbiddenException extends FieldException {} diff --git a/core/modules/field/lib/Drupal/field/FieldValidationException.php b/core/modules/field/lib/Drupal/field/FieldValidationException.php new file mode 100644 index 0000000000000000000000000000000000000000..668057bc15a14ef3e13252dfc61ed866b4351eed --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldValidationException.php @@ -0,0 +1,38 @@ +<?php + +/* + * @file + * Definition of Drupal\field\FieldValidationExeption. + */ + +namespace Drupal\field; + +/** + * Exception thrown by field_attach_validate() on field validation errors. + */ +class FieldValidationException extends FieldException { + + /** + * An array of field validation errors. + * + * @var array + */ + public $errors; + + /** + * Constructor for FieldValidationException. + * + * @param $errors + * An array of field validation errors, keyed by field name and + * delta that contains two keys: + * - 'error': A machine-readable error code string, prefixed by + * the field module name. A field widget may use this code to decide + * how to report the error. + * - 'message': A human-readable error message such as to be + * passed to form_error() for the appropriate form element. + */ + function __construct($errors) { + $this->errors = $errors; + parent::__construct(t('Field validation errors')); + } +} diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.module b/core/modules/field/modules/field_sql_storage/field_sql_storage.module index b3eed499957538f02ac814353a9654e790fe9fab..f9c27a8c3730eaadc03b2965509266c987edd7f9 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.module @@ -2,6 +2,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\Select; +use Drupal\field\FieldUpdateForbiddenException; /** * @file diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.test b/core/modules/field/modules/field_sql_storage/field_sql_storage.test index 87c388a174694cabf4ef43902f382b8ae236c9f5..20b5bdc52896c49279be653b8e1ba4fe1aa26ccd 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.test +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.test @@ -1,6 +1,7 @@ <?php use Drupal\Core\Database\Database; +use Drupal\field\FieldException; /** * @file diff --git a/core/modules/field/modules/list/list.module b/core/modules/field/modules/list/list.module index f0b1b80f972f15b56f1c0f964f9ad31dcf178eb2..c80773a3d47090e6c34539fe2bd8bd5d961c4936 100644 --- a/core/modules/field/modules/list/list.module +++ b/core/modules/field/modules/list/list.module @@ -5,6 +5,8 @@ * Defines list field types that can be used with the Options module. */ +use Drupal\field\FieldUpdateForbiddenException; + /** * Implements hook_help(). */ diff --git a/core/modules/field/modules/list/tests/list.test b/core/modules/field/modules/list/tests/list.test index f441f4d2c9450930576477fe994166c85eea5e9a..bdc96a63e68274546a1edca68f24091719379e04 100644 --- a/core/modules/field/modules/list/tests/list.test +++ b/core/modules/field/modules/list/tests/list.test @@ -5,6 +5,9 @@ * Tests for list.module. */ +use Drupal\field\FieldException; +use Drupal\field\FieldValidationException; + /** * Tests for the 'List' field types. */ diff --git a/core/modules/field/modules/text/text.test b/core/modules/field/modules/text/text.test index 0dbacccf3b2117cc8a4114fd2f5667137062f48c..d4f41f01cd4e6824e0e011214e842d09a14f04cf 100644 --- a/core/modules/field/modules/text/text.test +++ b/core/modules/field/modules/text/text.test @@ -5,6 +5,8 @@ * Tests for text.module. */ +use Drupal\field\FieldValidationException; + class TextFieldTestCase extends DrupalWebTestCase { protected $instance; protected $admin_user; diff --git a/core/modules/field/tests/field.test b/core/modules/field/tests/field.test index fc277a596c0610a24ae80b5c06afa0abf2f7a926..b8945a11e99edde127ebf915b33e322cb8fe81ad 100644 --- a/core/modules/field/tests/field.test +++ b/core/modules/field/tests/field.test @@ -5,6 +5,9 @@ * Tests for field.module. */ +use Drupal\field\FieldException; +use Drupal\field\FieldValidationException; + /** * Parent class for Field API tests. */ diff --git a/core/modules/field/tests/field_test.field.inc b/core/modules/field/tests/field_test.field.inc index cc76a998d955a9fece26561c6e1de6674d447693..8933d8b85f8b647509f1adc90ad116b57d72016f 100644 --- a/core/modules/field/tests/field_test.field.inc +++ b/core/modules/field/tests/field_test.field.inc @@ -5,6 +5,8 @@ * Defines a field type and its formatters and widgets. */ +use Drupal\field\FieldException; + /** * Implements hook_field_info(). */ diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test index a26d15f3e2a780a937976f80be92f93fe7bfc90d..eaac99c78e9bf892c08a932590d86dcd9a5827fc 100644 --- a/core/modules/taxonomy/taxonomy.test +++ b/core/modules/taxonomy/taxonomy.test @@ -5,6 +5,8 @@ * Tests for taxonomy.module. */ +use Drupal\field\FieldValidationException; + /** * Provides common helper methods for Taxonomy module tests. */