class SocialSimpleManager in Social simple 8
Same name and namespace in other branches
- 2.0.x src/SocialSimpleManager.php \Drupal\social_simple\SocialSimpleManager
Provides a social network manager.
Can be assigned any number of BreadcrumbBuilderInterface objects by calling the addBuilder() method. When build() is called it iterates over the objects in priority order and uses the first one that returns TRUE from BreadcrumbBuilderInterface::applies() to build the breadcrumbs.
Hierarchy
- class \Drupal\social_simple\SocialSimpleManager implements SocialSimpleManagerInterface
Expanded class hierarchy of SocialSimpleManager
See also
\Drupal\Core\DependencyInjection\Compiler\RegisterBreadcrumbBuilderPass
1 string reference to 'SocialSimpleManager'
1 service uses SocialSimpleManager
File
- src/
SocialSimpleManager.php, line 18
Namespace
Drupal\social_simpleView source
class SocialSimpleManager implements SocialSimpleManagerInterface {
/**
* The module handler to invoke the alter hook.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Holds arrays of social network builders, keyed by priority.
*
* @var array
*/
protected $networks = [];
/**
* Holds the array of social network builders sorted by priority.
*
* Set to NULL if the array needs to be re-calculated.
*
* @var \Drupal\social_simple\SocialNetwork\SocialNetworkInterface[]|null
*/
protected $sortedNetworks;
/**
* Constructs a \Drupal\Core\Breadcrumb\BreadcrumbManager object.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
*/
public function __construct(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public function addNetwork(SocialNetworkInterface $network, $priority) {
$network_id = $network
->getId();
$this->networks[$network_id][$priority][] = $network;
// Force the builders to be re-sorted.
$this->sortedNetworks = NULL;
}
/**
* {@inheritdoc}
*/
public function buildShareUrl($network_id) {
}
/**
* {@inheritdoc}
*/
public function getSortedNetworks() {
if (!isset($this->sortedNetworks)) {
foreach ($this->networks as $network_id => $networks_by_priority) {
krsort($this->networks[$network_id]);
$network_services = reset($this->networks[$network_id]);
$this->sortedNetworks[$network_id] = reset($network_services);
}
}
return $this->sortedNetworks;
}
/**
* {@inheritdoc}
*/
public function get($network_id) {
if (!isset($this->sortedNetworks[$network_id])) {
return [];
}
return $this->sortedNetworks[$network_id];
}
/**
* {@inheritdoc}
*/
public function getNetworks() {
foreach ($this
->getSortedNetworks() as $id => $network) {
$networks[$id] = $network
->getLabel();
}
return $networks;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SocialSimpleManager:: |
protected | property | The module handler to invoke the alter hook. | |
SocialSimpleManager:: |
protected | property | Holds arrays of social network builders, keyed by priority. | |
SocialSimpleManager:: |
protected | property | Holds the array of social network builders sorted by priority. | |
SocialSimpleManager:: |
public | function |
Adds another social network builder. Overrides SocialSimpleManagerInterface:: |
|
SocialSimpleManager:: |
public | function | ||
SocialSimpleManager:: |
public | function |
Gets the instantiated social network service. Overrides SocialSimpleManagerInterface:: |
|
SocialSimpleManager:: |
public | function |
Gets all the instantiated social networks. Overrides SocialSimpleManagerInterface:: |
|
SocialSimpleManager:: |
public | function |
Returns the sorted array of social network objects. Overrides SocialSimpleManagerInterface:: |
|
SocialSimpleManager:: |
public | function | Constructs a \Drupal\Core\Breadcrumb\BreadcrumbManager object. |