W3cubDocs

/Drupal 8

public function BlockBase::getMachineNameSuggestion

public BlockBase::getMachineNameSuggestion()

Suggests a machine name to identify an instance of this block.

The block plugin need not verify that the machine name is at all unique. It is only responsible for providing a baseline suggestion; calling code is responsible for ensuring whatever uniqueness is required for the use case.

Return value

string The suggested machine name.

Overrides BlockPluginInterface::getMachineNameSuggestion

File

core/lib/Drupal/Core/Block/BlockBase.php, line 237

Class

BlockBase
Defines a base block implementation that most blocks plugins will extend.

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 = Unicode::strtolower($transliterated);

  $transliterated = preg_replace('@[^a-z0-9_.]+@', '', $transliterated);

  return $transliterated;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Block!BlockBase.php/function/BlockBase::getMachineNameSuggestion/8.1.x