You are here

public function BlockBase::getMachineNameSuggestion in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Block/BlockBase.php \Drupal\Core\Block\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

1 method overrides BlockBase::getMachineNameSuggestion()
ViewsBlock::getMachineNameSuggestion in core/modules/views/src/Plugin/Block/ViewsBlock.php
Suggests a machine name to identify an instance of this block.

File

core/lib/Drupal/Core/Block/BlockBase.php, line 242
Contains \Drupal\Core\Block\BlockBase.

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;
}