Issue #1542682 by Berdir: Convert exception classes in field.module to PSR-0.

8.0.x
catch 2012-05-07 11:56:49 +09:00
parent 1bd03e00bf
commit fe01ab6e16
15 changed files with 99 additions and 43 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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()
*/

View File

@ -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().
*/

View File

@ -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 {}

View File

@ -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 {}

View File

@ -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'));
}
}

View File

@ -2,6 +2,7 @@
use Drupal\Core\Database\Database;
use Drupal\Core\Database\Query\Select;
use Drupal\field\FieldUpdateForbiddenException;
/**
* @file

View File

@ -1,6 +1,7 @@
<?php
use Drupal\Core\Database\Database;
use Drupal\field\FieldException;
/**
* @file

View File

@ -5,6 +5,8 @@
* Defines list field types that can be used with the Options module.
*/
use Drupal\field\FieldUpdateForbiddenException;
/**
* Implements hook_help().
*/

View File

@ -5,6 +5,9 @@
* Tests for list.module.
*/
use Drupal\field\FieldException;
use Drupal\field\FieldValidationException;
/**
* Tests for the 'List' field types.
*/

View File

@ -5,6 +5,8 @@
* Tests for text.module.
*/
use Drupal\field\FieldValidationException;
class TextFieldTestCase extends DrupalWebTestCase {
protected $instance;
protected $admin_user;

View File

@ -5,6 +5,9 @@
* Tests for field.module.
*/
use Drupal\field\FieldException;
use Drupal\field\FieldValidationException;
/**
* Parent class for Field API tests.
*/

View File

@ -5,6 +5,8 @@
* Defines a field type and its formatters and widgets.
*/
use Drupal\field\FieldException;
/**
* Implements hook_field_info().
*/

View File

@ -5,6 +5,8 @@
* Tests for taxonomy.module.
*/
use Drupal\field\FieldValidationException;
/**
* Provides common helper methods for Taxonomy module tests.
*/