You are here

class SimpleInstagramFeedLibrary in Simple Instagram Feed Block 8.3

Implements Simple Instagram Feed Library service.

Hierarchy

Expanded class hierarchy of SimpleInstagramFeedLibrary

1 string reference to 'SimpleInstagramFeedLibrary'
simple_instagram_feed.services.yml in ./simple_instagram_feed.services.yml
simple_instagram_feed.services.yml
1 service uses SimpleInstagramFeedLibrary
simple_instagram_feed.library in ./simple_instagram_feed.services.yml
Drupal\simple_instagram_feed\Services\SimpleInstagramFeedLibrary

File

src/Services/SimpleInstagramFeedLibrary.php, line 11

Namespace

Drupal\simple_instagram_feed\Services
View source
class SimpleInstagramFeedLibrary implements SimpleInstagramFeedLibraryInterface {
  use MessengerTrait;
  use StringTranslationTrait;

  /**
   * The drupal root path.
   *
   * @var string
   */
  private $root;

  /**
   * {@inheritdoc}
   */
  public function isAvailable(bool $warning = FALSE) {
    if (!file_exists($this->root . $this
      ->getPath())) {
      if ($warning) {
        $this
          ->messenger()
          ->addWarning($this
          ->getWarningMessage());
      }
      return FALSE;
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getWarningMessage() {
    return $this
      ->t('Missing library: The <a href=":url">jquery.instagramFeed</a> library should be installed at <strong>:path</strong>.', [
      ':url' => 'https://github.com/jsanahuja/jquery.instagramFeed',
      ':path' => $this
        ->getPath(),
    ]);
  }

  /**
   * Returns the expected js library path.
   */
  private function getPath() {
    return '/libraries/jqueryinstagramfeed/jquery.instagramFeed.min.js';
  }

  /**
   * {@inheritdoc}
   */
  public function __construct($root) {
    $this->root = $root;
  }

  /**
   * {@inheritdoc}
   */
  public function create(ContainerInterface $container) {
    return new static($container
      ->get('app.root'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
SimpleInstagramFeedLibrary::$root private property The drupal root path.
SimpleInstagramFeedLibrary::create public function
SimpleInstagramFeedLibrary::getPath private function Returns the expected js library path.
SimpleInstagramFeedLibrary::getWarningMessage public function Get the warning message. Overrides SimpleInstagramFeedLibraryInterface::getWarningMessage
SimpleInstagramFeedLibrary::isAvailable public function Check library avalilability. Overrides SimpleInstagramFeedLibraryInterface::isAvailable
SimpleInstagramFeedLibrary::__construct public function
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.