Objected-oriented programming conventions

PSR-4, namespaces, class naming, and other conventions. A lot of the PHP code in Drupal is object oriented (OO), making use of PHP classes, interfaces, and traits (which are loosely referred to as "classes" in the rest of this topic). The following conventions and standards apply to this version of Drupal: Each class must be in its own file. Classes must be namespaced. If a module defines a class, the namespace must start with \Drupal\module_name. If it is defined by Drupal Core for use across

Number::validStep

public static Number::validStep($value, $step, $offset = 0.0) Verifies that a number is a multiple of a given step. The implementation assumes it is dealing with IEEE 754 double precision floating point numbers that are used by PHP on most systems. This is based on the number/range verification methods of webkit. Parameters float $value: The value that needs to be checked. float $step: The step scale factor. Must be positive. float $offset: (optional) An offset, to which the difference must be

Number::validateNumber

public static Number::validateNumber(&$element, FormStateInterface $form_state, &$complete_form) Form element validation handler for #type 'number'. Note that #required is validated by _form_validate() already. File core/lib/Drupal/Core/Render/Element/Number.php, line 62 Class Number Provides a form element for numeric input, with special numeric validation. Namespace Drupal\Core\Render\Element Code public static function validateNumber(&$element, FormStateInterface $form_s

Number::preRenderNumber

public static Number::preRenderNumber($element) Prepares a #type 'number' render element for input.html.twig. Parameters array $element: An associative array containing the properties of the element. Properties used: #title, #value, #description, #min, #max, #placeholder, #required, #attributes, #step, #size. Return value array The $element with prepared variables ready for input.html.twig. File core/lib/Drupal/Core/Render/Element/Number.php, line 108 Class Number Provides a form element

Number::intToAlphadecimal

public static Number::intToAlphadecimal($i = 0) Generates a sorting code from an integer. Consists of a leading character indicating length, followed by N digits with a numerical value in base 36 (alphadecimal). These codes can be sorted as strings without altering numerical order. It goes: 00, 01, 02, ..., 0y, 0z, 110, 111, ... , 1zy, 1zz, 2100, 2101, ..., 2zzy, 2zzz, 31000, 31001, ... Parameters int $i: The integer value to convert. Return value string The alpha decimal value. See also \Dr

Number::getInfo

public Number::getInfo() Returns the element properties for this element. Return value array An array of element properties. See \Drupal\Core\Render\ElementInfoManagerInterface::getInfo() for documentation of the standard properties of all elements, and the return value format. Overrides ElementInterface::getInfo File core/lib/Drupal/Core/Render/Element/Number.php, line 38 Class Number Provides a form element for numeric input, with special numeric validation. Namespace Drupal\Core\Ren

Number::alphadecimalToInt

public static Number::alphadecimalToInt($string = '00') Decodes a sorting code back to an integer. Parameters string $string: The alpha decimal value to convert Return value int The integer value. See also \Drupal\Component\Utility\Number::intToAlphadecimal File core/lib/Drupal/Component/Utility/Number.php, line 97 Class Number Provides helper methods for manipulating numbers. Namespace Drupal\Component\Utility Code public static function alphadecimalToInt($string = '00') { return

Number

Provides a form element for numeric input, with special numeric validation. Properties: #default_value: A valid floating point number. #min: Minimum value. #max: Maximum value. #step: Ensures that the number is an even multiple of step, offset by #min if specified. A #min of 1 and a #step of 2 would allow values of 1, 3, 5, etc. Usage example: $form['quantity'] = array( '#type' => 'number', '#title' => $this->t('Quantity'), ); Plugin annotation @FormElement("number") Hierar

Number

Provides helper methods for manipulating numbers. Hierarchy class \Drupal\Component\Utility\Number Related topics Utility classes and functions Overview of utility classes and functions for developers. File core/lib/Drupal/Component/Utility/Number.php, line 10 Namespace Drupal\Component\Utility Members Name Modifiers Type Description Number::alphadecimalToInt public static function Decodes a sorting code back to an integer. Number::intToAlphadecimal public static

NullStorageExpirable::__construct

public NullStorageExpirable::__construct($collection) Creates a new expirable null key/value store. File core/lib/Drupal/Core/KeyValueStore/NullStorageExpirable.php, line 27 Class NullStorageExpirable Defines a null key/value store implementation. Namespace Drupal\Core\KeyValueStore Code public function __construct($collection) { $this->collection = $collection; }