You are here

class SocialSimpleManager in Social simple 2.0.x

Same name and namespace in other branches
  1. 8 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

Expanded class hierarchy of SocialSimpleManager

See also

\Drupal\Core\DependencyInjection\Compiler\RegisterBreadcrumbBuilderPass

1 string reference to 'SocialSimpleManager'
social_simple.services.yml in ./social_simple.services.yml
social_simple.services.yml
1 service uses SocialSimpleManager
social_simple.manager in ./social_simple.services.yml
Drupal\social_simple\SocialSimpleManager

File

src/SocialSimpleManager.php, line 18

Namespace

Drupal\social_simple
View 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

Namesort descending Modifiers Type Description Overrides
SocialSimpleManager::$moduleHandler protected property The module handler to invoke the alter hook.
SocialSimpleManager::$networks protected property Holds arrays of social network builders, keyed by priority.
SocialSimpleManager::$sortedNetworks protected property Holds the array of social network builders sorted by priority.
SocialSimpleManager::addNetwork public function Adds another social network builder. Overrides SocialSimpleManagerInterface::addNetwork
SocialSimpleManager::buildShareUrl public function
SocialSimpleManager::get public function Gets the instantiated social network service. Overrides SocialSimpleManagerInterface::get
SocialSimpleManager::getNetworks public function Gets all the instantiated social networks. Overrides SocialSimpleManagerInterface::getNetworks
SocialSimpleManager::getSortedNetworks public function Returns the sorted array of social network objects. Overrides SocialSimpleManagerInterface::getSortedNetworks
SocialSimpleManager::__construct public function Constructs a \Drupal\Core\Breadcrumb\BreadcrumbManager object.