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' => [],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment