Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Extension.php

function Extension::getAlias

Returns the recommended alias to use in XML.

This alias is also the mandatory prefix to use when using YAML.

This convention is to remove the "Extension" postfix from the class name and then lowercase and underscore the result. So:

AcmeHelloExtension

becomes

acme_hello

This can be overridden in a sub-class to specify the alias manually.

Throws

BadMethodCallException When the extension name does not follow conventions

Overrides ExtensionInterface::getAlias

2 calls to Extension::getAlias()
AbstractExtension::getConfiguration in vendor/symfony/dependency-injection/Extension/AbstractExtension.php
Returns extension configuration.
Extension::getNamespace in vendor/symfony/dependency-injection/Extension/Extension.php
1 method overrides Extension::getAlias()
BundleExtension::getAlias in vendor/symfony/http-kernel/Bundle/BundleExtension.php
Returns the recommended alias to use in XML.

File

vendor/symfony/dependency-injection/Extension/Extension.php, line 65

Class

Extension
Provides useful features shared by many extensions.

Namespace

Symfony\Component\DependencyInjection\Extension

Code

public function getAlias() : string {
    $className = static::class;
    if (!str_ends_with($className, 'Extension')) {
        throw new BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
    }
    $classBaseName = substr(strrchr($className, '\\'), 1, -9);
    return Container::underscore($classBaseName);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal