Commit eafefd89 authored by catch's avatar catch
Browse files

Issue #2619482 by cburschka, ankit.singh, ravi.shankar, jungle, daffie:...

Issue #2619482 by cburschka, ankit.singh, ravi.shankar, jungle, daffie: Convert all get_called_class()/get_class() to static::
parent 488b2cee
......@@ -360,7 +360,7 @@ public function __call($method, array $args) {
throw new \Exception('DateTime object not set.');
}
if (!method_exists($this->dateTimeObject, $method)) {
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $method));
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class, $method));
}
$result = call_user_func_array([$this->dateTimeObject, $method], $args);
......@@ -399,7 +399,7 @@ public function diff($datetime2, $absolute = FALSE) {
*/
public static function __callStatic($method, $args) {
if (!method_exists('\DateTime', $method)) {
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_called_class(), $method));
throw new \BadMethodCallException(sprintf('Call to undefined method %s::%s()', static::class, $method));
}
return call_user_func_array(['\DateTime', $method], $args);
}
......
......@@ -17,7 +17,7 @@ public function __toString() {
catch (\Exception $e) {
// User errors in __toString() methods are considered fatal in the Drupal
// error handler.
trigger_error(get_class($e) . ' thrown while calling __toString on a ' . get_class($this) . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_ERROR);
trigger_error(get_class($e) . ' thrown while calling __toString on a ' . static::class . ' object in ' . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage(), E_USER_ERROR);
// In case we are using another error handler that did not fatal on the
// E_USER_ERROR, we terminate execution. However, for test purposes allow
// a return value.
......
......@@ -79,7 +79,7 @@ public static function filter($string, array $html_tags = NULL) {
$string = preg_replace('/&([A-Za-z][A-Za-z0-9]*;)/', '&\1', $string);
$html_tags = array_flip($html_tags);
// Late static binding does not work inside anonymous functions.
$class = get_called_class();
$class = static::class;
$splitter = function ($matches) use ($html_tags, $class) {
return $class::split($matches[1], $html_tags, $class);
};
......
......@@ -1822,7 +1822,7 @@ public static function createConnectionOptionsFromUrl($url, $root) {
}
// Use reflection to get the namespace of the class being called.
$reflector = new \ReflectionClass(get_called_class());
$reflector = new \ReflectionClass(static::class);
$database = [
'driver' => $url_components['scheme'],
......
......@@ -18,7 +18,7 @@ class Datelist extends DateElementBase {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#element_validate' => [
......
......@@ -37,7 +37,7 @@ public function getInfo() {
}
}
$class = get_class($this);
$class = static::class;
// Note that since this information is cached, the #date_timezone property
// is not set here, as this needs to vary potentially by-user.
......
......@@ -26,7 +26,7 @@ class EntityAutocomplete extends Textfield {
*/
public function getInfo() {
$info = parent::getInfo();
$class = get_class($this);
$class = static::class;
// Apply default form element properties.
$info['#target_type'] = NULL;
......
......@@ -484,7 +484,7 @@ public function getCacheMaxAge() {
public static function load($id) {
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(static::class));
return $storage->load($id);
}
......@@ -494,7 +494,7 @@ public static function load($id) {
public static function loadMultiple(array $ids = NULL) {
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(static::class));
return $storage->loadMultiple($ids);
}
......@@ -504,7 +504,7 @@ public static function loadMultiple(array $ids = NULL) {
public static function create(array $values = []) {
$entity_type_repository = \Drupal::service('entity_type.repository');
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
$storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(static::class));
return $storage->create($values);
}
......
......@@ -177,7 +177,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
'#required' => TRUE,
'#size' => 6,
'#multiple' => TRUE,
'#element_validate' => [[get_class($this), 'elementValidateFilter']],
'#element_validate' => [[static::class, 'elementValidateFilter']],
'#ajax' => TRUE,
'#limit_validation_errors' => [],
];
......
......@@ -390,8 +390,8 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$form = [
'#type' => 'container',
'#process' => [[get_class($this), 'fieldSettingsAjaxProcess']],
'#element_validate' => [[get_class($this), 'fieldSettingsFormValidate']],
'#process' => [[static::class, 'fieldSettingsAjaxProcess']],
'#element_validate' => [[static::class, 'fieldSettingsFormValidate']],
];
$form['handler'] = [
......@@ -399,7 +399,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
'#title' => t('Reference type'),
'#open' => TRUE,
'#tree' => TRUE,
'#process' => [[get_class($this), 'formProcessMergeParent']],
'#process' => [[static::class, 'formProcessMergeParent']],
];
$form['handler']['handler'] = [
......@@ -418,7 +418,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
'#attributes' => [
'class' => ['js-hide'],
],
'#submit' => [[get_class($this), 'settingsAjaxSubmit']],
'#submit' => [[static::class, 'settingsAjaxSubmit']],
];
$form['handler']['handler_settings'] = [
......@@ -637,7 +637,7 @@ public static function fieldSettingsAjaxProcess($form, FormStateInterface $form_
public static function fieldSettingsAjaxProcessElement(&$element, $main_form) {
if (!empty($element['#ajax'])) {
$element['#ajax'] = [
'callback' => [get_called_class(), 'settingsAjax'],
'callback' => [static::class, 'settingsAjax'],
'wrapper' => $main_form['#id'],
'element' => $main_form['#array_parents'],
];
......
......@@ -50,7 +50,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$this->has_value = isset($items[0]->{$this->column});
// Add our custom validator.
$element['#element_validate'][] = [get_class($this), 'validateElement'];
$element['#element_validate'][] = [static::class, 'validateElement'];
$element['#key_column'] = $this->column;
// The rest of the $element is built by child method implementations.
......
......@@ -127,7 +127,7 @@ public function form(FieldItemListInterface $items, array &$form, FormStateInter
// Populate the 'array_parents' information in $form_state->get('field')
// after the form is built, so that we catch changes in the form structure
// performed in alter() hooks.
$elements['#after_build'][] = [get_class($this), 'afterBuild'];
$elements['#after_build'][] = [static::class, 'afterBuild'];
$elements['#field_name'] = $field_name;
$elements['#field_parents'] = $parents;
// Enforce the structure of submitted values.
......@@ -253,9 +253,9 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
'#value' => t('Add another item'),
'#attributes' => ['class' => ['field-add-more-submit']],
'#limit_validation_errors' => [array_merge($parents, [$field_name])],
'#submit' => [[get_class($this), 'addMoreSubmit']],
'#submit' => [[static::class, 'addMoreSubmit']],
'#ajax' => [
'callback' => [get_class($this), 'addMoreAjax'],
'callback' => [static::class, 'addMoreAjax'],
'wrapper' => $wrapper_id,
'effect' => 'fade',
],
......
......@@ -30,7 +30,7 @@ class Actions extends Container {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#process' => [
// @todo Move this to #pre_render.
......
......@@ -36,7 +36,7 @@ class Button extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#name' => 'op',
......
......@@ -29,7 +29,7 @@ class Checkbox extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#return_value' => 1,
......
......@@ -36,7 +36,7 @@ class Checkboxes extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#process' => [
......
......@@ -29,7 +29,7 @@ class Color extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#process' => [
......
......@@ -49,7 +49,7 @@ class Container extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#optional' => FALSE,
'#process' => [
......
......@@ -28,7 +28,7 @@ class Date extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#theme' => 'input__date',
......
......@@ -42,7 +42,7 @@ class Details extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#open' => FALSE,
'#summary_attributes' => [],
......
......@@ -48,7 +48,7 @@ class Dropbutton extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#pre_render' => [
[$class, 'preRenderDropbutton'],
......
......@@ -44,7 +44,7 @@ class Email extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
......
......@@ -29,7 +29,7 @@ class Fieldset extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#process' => [
[$class, 'processGroup'],
......
......@@ -23,7 +23,7 @@ class File extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#multiple' => FALSE,
......
......@@ -108,7 +108,7 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
public static function processPattern(&$element, FormStateInterface $form_state, &$complete_form) {
if (isset($element['#pattern']) && !isset($element['#attributes']['pattern'])) {
$element['#attributes']['pattern'] = $element['#pattern'];
$element['#element_validate'][] = [get_called_class(), 'validatePattern'];
$element['#element_validate'][] = [static::class, 'validatePattern'];
}
return $element;
......
......@@ -30,7 +30,7 @@ class Hidden extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#process' => [
......
......@@ -48,7 +48,7 @@ class HtmlTag extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#pre_render' => [
[$class, 'preRenderConditionalComments'],
......
......@@ -29,7 +29,7 @@ class InlineTemplate extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#pre_render' => [
[$class, 'preRenderInlineTemplate'],
......
......@@ -33,7 +33,7 @@ class Link extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#pre_render' => [
[$class, 'preRenderLink'],
......
......@@ -75,7 +75,7 @@ class MachineName extends Textfield {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#default_value' => NULL,
......
......@@ -36,7 +36,7 @@ class Number extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#step' => 1,
......
......@@ -38,7 +38,7 @@ class Pager extends RenderElement {
public function getInfo() {
return [
'#pre_render' => [
get_class($this) . '::preRenderPager',
static::class . '::preRenderPager',
],
'#theme' => 'pager',
// The pager ID, to distinguish between multiple pagers on the same page.
......
......@@ -33,7 +33,7 @@ class Password extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
......
......@@ -32,7 +32,7 @@ class PasswordConfirm extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#markup' => '',
......@@ -90,7 +90,7 @@ public static function processPasswordConfirm(&$element, FormStateInterface $for
],
'#error_no_message' => TRUE,
];
$element['#element_validate'] = [[get_called_class(), 'validatePasswordConfirm']];
$element['#element_validate'] = [[static::class, 'validatePasswordConfirm']];
$element['#tree'] = TRUE;
if (isset($element['#size'])) {
......
......@@ -35,7 +35,7 @@ class PathElement extends Textfield {
*/
public function getInfo() {
$info = parent::getInfo();
$class = get_class($this);
$class = static::class;
$info['#validate_path'] = TRUE;
$info['#convert_path'] = self::CONVERT_ROUTE;
$info['#element_validate'] = [
......
......@@ -21,7 +21,7 @@ class Radio extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#default_value' => NULL,
......
......@@ -36,7 +36,7 @@ class Radios extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#process' => [
......
......@@ -34,7 +34,7 @@ class Range extends Number {
*/
public function getInfo() {
$info = parent::getInfo();
$class = get_class($this);
$class = static::class;
return [
'#min' => 0,
'#max' => 100,
......
......@@ -25,7 +25,7 @@ class Search extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
......
......@@ -85,7 +85,7 @@ class Select extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#multiple' => FALSE,
......
......@@ -13,7 +13,7 @@ class StatusReport extends RenderElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#theme' => 'status_report_grouped',
'#priorities' => [
......
......@@ -24,7 +24,7 @@ class SystemCompactLink extends Link {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#pre_render' => [
[$class, 'preRenderCompactLink'],
......
......@@ -63,7 +63,7 @@ class Table extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#header' => [],
'#rows' => [],
......
......@@ -56,7 +56,7 @@ class Tableselect extends Table {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#js_select' => TRUE,
......
......@@ -33,7 +33,7 @@ class Tel extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 30,
......
......@@ -33,7 +33,7 @@ class Textarea extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#cols' => 60,
......
......@@ -48,7 +48,7 @@ class Textfield extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
......
......@@ -20,7 +20,7 @@ class Token extends Hidden {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#pre_render' => [
......
......@@ -35,7 +35,7 @@ class Url extends FormElement {
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
$class = static::class;
return [
'#input' => TRUE,
'#size' => 60,
......