class CarouselService in bootstrap simple carousel 8
CarouselService Class.
Provides functions for the module.
@category Class @package Drupal\bootstrap_simple_carousel\Service
Hierarchy
- class \Drupal\Core\DependencyInjection\ServiceProviderBase implements ServiceModifierInterface, ServiceProviderInterface
- class \Drupal\bootstrap_simple_carousel\Service\CarouselService uses StringTranslationTrait
Expanded class hierarchy of CarouselService
3 files declare their use of CarouselService
- CarouselServiceTest.php in tests/
src/ Unit/ Service/ CarouselServiceTest.php - EditForm.php in src/
Form/ EditForm.php - ItemsForm.php in src/
Form/ ItemsForm.php
1 string reference to 'CarouselService'
1 service uses CarouselService
File
- src/
Service/ CarouselService.php, line 17
Namespace
Drupal\bootstrap_simple_carousel\ServiceView source
class CarouselService extends ServiceProviderBase {
use \Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* This will hold Renderer object.
*
* @var \Drupal\Core\Render\Renderer
*/
protected $renderer;
/**
* This will hold File object.
*
* @var \Drupal\file\FileInterface
*/
protected $file;
/**
* CarouselService constructor.
*
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity manager interface.
*/
public function __construct(RendererInterface $renderer, EntityTypeManagerInterface $entityTypeManager) {
$this->renderer = $renderer;
$this->file = $entityTypeManager
->getStorage('file');
}
/**
* Return a rendered image.
*
* @param int $image_id
* The image id for the carousel.
* @param string $image_style
* The image style for the carousel.
* @param array $params
* An array of parameters.
*
* @throws \Exception
*
* @return string
* Rendered image
*/
public function renderImageById($image_id, $image_style = 'thumbnail', array $params = []) {
$image = '';
$imageFile = $this->file
->load($image_id);
if (!empty($imageFile)) {
$imageTheme = [
'#theme' => 'image_style',
'#style_name' => $image_style,
'#uri' => $imageFile
->getFileUri(),
'#alt' => $params['alt'] ?? '',
'#title' => $params['title'] ?? '',
];
$image = $this->renderer
->render($imageTheme);
}
return $image;
}
/**
* Return a Render Link.
*
* @param string $url
* The url for the render link.
* @param string $title
* The title for the render link.
* @param array $attributes
* The array of attributes.
*
* @throws \Exception
*
* @return string
* Rendered link
*/
public function renderLink($url, $title, array $attributes = []) {
$linkTheme = [
'#type' => 'link',
'#title' => $title,
'#url' => $url,
'#options' => [
'attributes' => $attributes,
'html' => FALSE,
],
];
$link = $this->renderer
->render($linkTheme);
return $link;
}
/**
* Return the statuses.
*
* @return array
* Of statuses
*/
public function getStatuses() {
return [
0 => $this
->t('Inactive'),
1 => $this
->t('Active'),
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CarouselService:: |
protected | property | This will hold File object. | |
CarouselService:: |
protected | property | This will hold Renderer object. | |
CarouselService:: |
public | function | Return the statuses. | |
CarouselService:: |
public | function | Return a rendered image. | |
CarouselService:: |
public | function | Return a Render Link. | |
CarouselService:: |
public | function | CarouselService constructor. | |
ServiceProviderBase:: |
public | function |
Modifies existing service definitions. Overrides ServiceModifierInterface:: |
5 |
ServiceProviderBase:: |
public | function |
Registers services to the container. Overrides ServiceProviderInterface:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |