function BlockPluginTrait::getMachineNameSuggestion

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::getMachineNameSuggestion()
  2. 10 core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::getMachineNameSuggestion()
  3. 11.x core/lib/Drupal/Core/Block/BlockPluginTrait.php \Drupal\Core\Block\BlockPluginTrait::getMachineNameSuggestion()
1 method overrides BlockPluginTrait::getMachineNameSuggestion()
ViewsBlock::getMachineNameSuggestion in core/modules/views/src/Plugin/Block/ViewsBlock.php

File

core/lib/Drupal/Core/Block/BlockPluginTrait.php, line 247

Class

BlockPluginTrait
Provides the base implementation of a block plugin.

Namespace

Drupal\Core\Block

Code

public function getMachineNameSuggestion() {
    $definition = $this->getPluginDefinition();
    $admin_label = $definition['admin_label'];
    // @todo This is basically the same as what is done in
    //   \Drupal\system\MachineNameController::transliterate(), so it might make
    //   sense to provide a common service for the two.
    $transliterated = $this->transliteration()
        ->transliterate($admin_label, LanguageInterface::LANGCODE_DEFAULT, '_');
    $transliterated = mb_strtolower($transliterated);
    $transliterated = preg_replace('@[^a-z0-9_.]+@', '', $transliterated);
    return $transliterated;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.