Created
May 31, 2016 18:25
-
-
Save gvso/d5adaf3c4bde9321d6841b52bd963646 to your computer and use it in GitHub Desktop.
Local Tasks Deriver for Facebook Widgets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Contains \Drupal\facebook_widgets\Plugin\Derivative\DynamicLocalTasks. | |
*/ | |
namespace Drupal\facebook_widgets\Plugin\Derivative; | |
use Drupal\Component\Plugin\Derivative\DeriverBase; | |
use Drupal\Core\Menu\LocalTaskManager; | |
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; | |
use Symfony\Component\DependencyInjection\ContainerInterface; | |
/** | |
* Class DynamicLocalTasks | |
* | |
* @package Drupal\example\Plugin\Derivative | |
*/ | |
class FacebookWidgetsLocalTasks extends DeriverBase implements ContainerDeriverInterface { | |
/** | |
* The base plugin ID. | |
* | |
* @var string | |
*/ | |
private $basePluginId; | |
/** | |
* The local task manager | |
* | |
* @var array | |
*/ | |
private $localTasks = array(); | |
private $called = false; | |
public function __construct($basePluginId, LocalTaskManager $localTaskManager) { | |
$this->basePluginId = $basePluginId; | |
$this->localTasks = $localTaskManager->getDefinitions(); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getDerivativeDefinitions($base_plugin_definition) { | |
// Implement dynamic logic to provide values for the same keys as in example.links.task.yml. | |
$this->derivatives['facebook_widgets.list'] = $base_plugin_definition; | |
$tasksList = $this->localTasks; | |
foreach($tasksList as $task) { | |
if($task['parent_id'] == 'facebook_widgets.list') { | |
$this->derivatives['facebook_widgets.list']['route_name'] = 'facebook_comments.settings'; | |
break; | |
} | |
} | |
return $this->derivatives; | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function create(ContainerInterface $container, $base_plugin_id) { | |
return new static( | |
$base_plugin_id, | |
$container->get('plugin.manager.menu.local_task') | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment