From fe01ab6e16a73a43dc193c1571b86e79363784b1 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
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 2448d738adb6..44aa50b53c8d 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 ff579c7b4c6a..cf597f0d9620 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 f9c96c92b020..4a4842f19d09 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 eabcf2a29a0b..ab67eb26316b 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 000000000000..b653109f7194
--- /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 000000000000..6bf914f17b96
--- /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 000000000000..668057bc15a1
--- /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 b3eed4999575..f9c27a8c3730 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 87c388a17469..20b5bdc52896 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 f0b1b80f972f..c80773a3d470 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 f441f4d2c945..bdc96a63e682 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 0dbacccf3b21..d4f41f01cd4e 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 fc277a596c06..b8945a11e99e 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 cc76a998d955..8933d8b85f8b 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 a26d15f3e2a7..eaac99c78e9b 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.
  */
-- 
GitLab