From fe01ab6e16a73a43dc193c1571b86e79363784b1 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 7 May 2012 11:56:49 +0900 Subject: [PATCH] Issue #1542682 by Berdir: Convert exception classes in field.module to PSR-0. --- core/modules/field/field.api.php | 5 ++- core/modules/field/field.attach.inc | 26 +------------ core/modules/field/field.crud.inc | 13 ++++--- core/modules/field/field.module | 13 ------- .../field/lib/Drupal/field/FieldException.php | 18 +++++++++ .../field/FieldUpdateForbiddenException.php | 13 +++++++ .../Drupal/field/FieldValidationException.php | 38 +++++++++++++++++++ .../field_sql_storage.module | 1 + .../field_sql_storage/field_sql_storage.test | 1 + core/modules/field/modules/list/list.module | 2 + .../field/modules/list/tests/list.test | 3 ++ core/modules/field/modules/text/text.test | 2 + core/modules/field/tests/field.test | 3 ++ core/modules/field/tests/field_test.field.inc | 2 + core/modules/taxonomy/taxonomy.test | 2 + 15 files changed, 99 insertions(+), 43 deletions(-) create mode 100644 core/modules/field/lib/Drupal/field/FieldException.php create mode 100644 core/modules/field/lib/Drupal/field/FieldUpdateForbiddenException.php create mode 100644 core/modules/field/lib/Drupal/field/FieldValidationException.php diff --git a/core/modules/field/field.api.php b/core/modules/field/field.api.php index 2448d738adb..44aa50b53c8 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 ff579c7b4c6..cf597f0d962 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 f9c96c92b02..4a4842f19d0 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 eabcf2a29a0..ab67eb26316 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 @@ const FIELD_LOAD_CURRENT = 'FIELD_LOAD_CURRENT'; */ 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 00000000000..b653109f719 --- /dev/null +++ b/core/modules/field/lib/Drupal/field/FieldException.php @@ -0,0 +1,18 @@ +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 b3eed499957..f9c27a8c373 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 87c388a1746..20b5bdc5289 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 @@