You are here

class ExampleClass in Coder 8.3.x

Same name and namespace in other branches
  1. 8.3 tests/DrupalPractice/Objects/drupal8/ExampleClass.php \Drupal\testmodule\ExampleClass

A class which is not a service.

Hierarchy

Expanded class hierarchy of ExampleClass

File

tests/DrupalPractice/Objects/drupal8/ExampleClass.php, line 10

Namespace

Drupal\testmodule
View source
class ExampleClass {

  /**
   * Using \Drupal here is allowed since this class cannot access the container.
   */
  public function test() {
    return \Drupal::configFactory();
  }

  /**
   * Loading nodes directly is allowed since we cannot access the container.
   */
  public function test2() {
    return Node::load(1);
  }

  /**
   * Global function is allowed since we cannot access the container.
   */
  public function test3() {
    return format_date(time());
  }

  /**
   * t() should not be used, instead we should use the StringTranslationTrait.
   */
  public function test4() {
    return t('Test');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExampleClass::test public function Using \Drupal here is allowed since this class cannot access the container.
ExampleClass::test2 public function Loading nodes directly is allowed since we cannot access the container.
ExampleClass::test3 public function Global function is allowed since we cannot access the container.
ExampleClass::test4 public function t() should not be used, instead we should use the StringTranslationTrait.