You are here

class ContactLocalTaskProvider in CRM Core 8.3

Provides a set of tasks to view, edit and duplicate an entity.

Hierarchy

Expanded class hierarchy of ContactLocalTaskProvider

1 file declares its use of ContactLocalTaskProvider
LocalTaskTest.php in modules/crm_core_contact/tests/src/Kernel/LocalTaskTest.php

File

modules/crm_core_contact/src/Menu/ContactLocalTaskProvider.php, line 11

Namespace

Drupal\crm_core_contact\Menu
View source
class ContactLocalTaskProvider extends DefaultEntityLocalTaskProvider {

  /**
   * {@inheritdoc}
   */
  public function buildLocalTasks(EntityTypeInterface $entity_type) {

    // See #1834002 and #3044371 for context.
    $link_templates = [];
    $types = [
      'canonical',
      'edit-form',
      'duplicate-form',
      'delete-form',
      'version-history',
    ];
    foreach ($types as $type) {
      if ($entity_type
        ->hasLinkTemplate($type)) {
        $link_templates[] = str_replace('-', '_', $type);
      }
    }
    $tasks = [];
    if (count($link_templates) > 1) {
      $entity_type_id = $entity_type
        ->id();
      $base = reset($link_templates);
      $titles = [
        'canonical' => $this
          ->t('View'),
        'edit_form' => $this
          ->t('Edit'),
        'duplicate_form' => $this
          ->t('Duplicate'),
        'delete_form' => $this
          ->t('Delete'),
        'version_history' => $this
          ->t('Revisions'),
      ];
      $weight = 0;
      foreach ($link_templates as $template) {
        $route_name = "entity.{$entity_type_id}.{$template}";
        $tasks[$route_name] = [
          'title' => $titles[$template],
          'route_name' => $route_name,
          'base_route' => "entity.{$entity_type_id}.{$base}",
          'weight' => $weight,
        ];
        $weight += 10;
      }
    }
    return $tasks;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContactLocalTaskProvider::buildLocalTasks public function Builds local tasks for the given entity type. Overrides DefaultEntityLocalTaskProvider::buildLocalTasks
DefaultEntityLocalTaskProvider::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
DefaultEntityLocalTaskProvider::__construct public function Constructs a DefaultEntityLocalTaskProvider object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.