class FlickrFilter in Flickr 8
Provides a filter to insert Flickr photo.
Plugin annotation
@Filter(
id = "flickr_filter",
title = @Translation("Embed Flickr photo"),
description = @Translation("Allow users to embed a picture from Flickr website in an editable content area."),
type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
settings = {
"flickr_filter_imagesize" = 200,
},
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\filter\Plugin\FilterBase implements FilterInterface
- class \Drupal\flickr_filter\Plugin\Filter\FlickrFilter implements ContainerFactoryPluginInterface
- class \Drupal\filter\Plugin\FilterBase implements FilterInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of FlickrFilter
File
- modules/
flickr_filter/ src/ Plugin/ Filter/ FlickrFilter.php, line 27
Namespace
Drupal\flickr_filter\Plugin\FilterView source
class FlickrFilter extends FilterBase implements ContainerFactoryPluginInterface {
/**
* Helpers.
*
* @var \Drupal\flickr\Service\Helpers
*/
protected $helpers;
/**
* Photos.
*
* @var \Drupal\flickr\Service\Photos
*/
protected $photos;
/**
* Photosets.
*
* @var \Drupal\flickr\Service\Photosets
*/
protected $photosets;
/**
* FlickrFilter constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\flickr\Service\Helpers $helpers
* Helpers.
* @param \Drupal\flickr\Service\Photos $photos
* Photos.
* @param \Drupal\flickr\Service\Photosets $photosets
* Photosets.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Helpers $helpers, Photos $photos, Photosets $photosets) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->helpers = $helpers;
$this->photos = $photos;
$this->photosets = $photosets;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('flickr.helpers'), $container
->get('flickr.photos'), $container
->get('flickr.photosets'));
}
/**
* {@inheritdoc}
*/
public function process($text, $langcode) {
$text = preg_replace_callback('/\\[flickr-photo:(.+?)\\]/', 'self::callbackPhoto', $text);
$text = preg_replace_callback('/\\[flickr-photoset:(.+?)\\]/', 'self::callbackPhotosets', $text);
// TODO Implement the rest of the options.
// @codingStandardsIgnoreStart
// $text = preg_replace_callback('/\[flickr-group:(.+?)\]/', 'flickr_filter_callback_group', $text);
// $text = preg_replace_callback('/\[flickr-gallery:(.+?)\]/', 'flickr_filter_callback_gallery', $text);
// $text = preg_replace_callback('/\[flickr-user:(.+?)\]/', 'flickr_filter_callback_album', $text);
// $text = preg_replace_callback('/\[flickr-favorites:(.+?)\]/', 'flickr_filter_callback_favorites', $text);.
// @codingStandardsIgnoreEnd
return new FilterProcessResult($text);
}
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$sizes = $this->helpers->flickrApiHelpers
->photoSizes();
foreach ($sizes as $key => $size) {
$options[$key] = $size['description']
->render();
}
$form['flickr_filter_default_size'] = [
'#type' => 'select',
'#title' => $this
->t('Default size for single photos'),
'#default_value' => $this->settings['flickr_filter_default_size'],
'#options' => $options,
'#description' => $this
->t("A default Flickr size to use if no size is specified, for example [flickr-photo:id=3711935987].<br />TAKE CARE, the c size (800px) is missing on Flickr images uploaded before March 1, 2012!"),
];
$form['flickr_filter_caption'] = [
'#type' => 'select',
'#title' => $this
->t('Display captions for every Flickr photo'),
'#required' => TRUE,
'#default_value' => $this->settings['flickr_filter_caption'],
'#description' => $this
->t("If selected, flickr photos will display caption."),
'#options' => [
0 => 'No',
1 => 'Yes',
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
// TODO Make this text a bit more informative.
if ($long) {
return $this
->t('Embed Flickr photos using @embed. Values for imagesize is optional, if left off the default values configured on the %filter input filter will be used', [
'@embed' => '[flickr-photo:id=<photo_id>, size=<imagesize>]',
'%filter' => 'Embed Flickr photo',
]);
}
else {
return $this
->t('Embed Flickr photo using @embed', [
'@embed' => '[flickr-photo:id=<photo_id>, size=<imagesize>]',
]);
}
}
/**
* Filter callback for a photo.
*/
private function callbackPhoto($matches) {
list($config, $attribs) = $this->helpers
->splitConfig($matches[1]);
if (isset($config['id'])) {
if ($photo = $this->photos->flickrApiPhotos
->photosGetInfo($config['id'])) {
if (!isset($config['size'])) {
$config['size'] = $this->settings['flickr_filter_default_size'];
}
if (!isset($config['caption'])) {
$config['caption'] = $this->settings['flickr_filter_caption'];
}
switch ($config['size']) {
case "x":
case "y":
$this
->messenger()
->addError($this
->t("Do not use a slideshow for a single image."));
$config['size'] = $this->settings['flickr_filter_default_size'];
break;
}
$photoimg = $this->photos
->themePhoto($photo, $config['size'], $config['caption']);
return render($photoimg);
}
}
return '';
}
/**
* Filter callback for a user or set.
*/
public function callbackPhotosets($matches) {
list($config, $attribs) = $this->helpers
->splitConfig($matches[1]);
// Class.
// TODO Implement this.
if (!isset($attribs['class'])) {
$attribs['class'] = NULL;
}
// Style.
// TODO Implement this.
if (!isset($attribs['style'])) {
$attribs['style'] = NULL;
}
// Size.
if (!isset($config['size'])) {
$config['size'] = NULL;
}
// Photo count.
if (!isset($config['num'])) {
$config['num'] = NULL;
}
// Media.
if (!isset($config['media'])) {
$config['media'] = 'photos';
}
// Tags.
if (!isset($config['tags'])) {
$config['tags'] = '';
}
else {
$config['tags'] = str_replace("/", ",", $config['tags']);
}
// Location options.
if (!isset($config['location'])) {
$config['location'][0] = NULL;
$config['location'][1] = NULL;
$config['location'][2] = NULL;
}
else {
$config['location'] = explode("/", $config['location']);
if (!isset($config['location'][2])) {
$config['location'][2] = NULL;
}
}
// Date options.
if (!isset($config['date'])) {
$config['date'][0] = NULL;
$config['date'][1] = NULL;
}
else {
$config['date'] = explode("|", $config['date']);
if (!isset($config['date'][1])) {
$config['date'][1] = NULL;
}
}
// Sort options.
if (!isset($config['sort'])) {
$config['sort'] = 'unsorted';
}
switch ($config['sort']) {
case 'taken':
$config['sort'] = 'date-taken-desc';
break;
case 'posted':
$config['sort'] = 'date-posted-desc';
break;
}
// Show Caption.
if (!isset($config['caption'])) {
$config['caption'] = $this->settings['flickr_filter_caption'];
}
// Tag Mode.
if (!isset($config['tag_mode'])) {
$config['tag_mode'] = 'context';
}
// Mintitle?
// TODO Implement this.
if (!isset($config['mintitle'])) {
$config['mintitle'] = NULL;
}
// Minmetsdata?
// TODO Implement this.
if (!isset($config['minmetadata'])) {
$config['minmetadata'] = NULL;
}
// Filter
// TODO Implement this.
if (!isset($config['filter'])) {
$config['filter'] = NULL;
}
switch ($config['filter']) {
case 'interesting':
$config['filter'] = 'interestingness-desc';
break;
case 'relevant':
$config['filter'] = 'relevance';
break;
}
// Showtime.
$photosetPhotos = $this->photosets->flickrApiPhotosets
->photosetsGetPhotos($config['id'], [
'per_page' => (int) $config['num'],
'media' => 'photos',
], 1);
$photos = $this->photos
->themePhotos($photosetPhotos['photo'], $config['size'], $config['caption'], $photosetPhotos['id']);
$photoset = $this->photosets
->themePhotoset($photos, $photosetPhotos['title']);
return render($photoset);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FilterBase:: |
public | property | The name of the provider that owns this filter. | |
FilterBase:: |
public | property | An associative array containing the configured settings of this filter. | |
FilterBase:: |
public | property | A Boolean indicating whether this filter is enabled. | |
FilterBase:: |
public | property | The weight of this filter compared to others in a filter collection. | |
FilterBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
1 |
FilterBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
FilterBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
FilterBase:: |
public | function |
Returns the administrative description for this filter plugin. Overrides FilterInterface:: |
|
FilterBase:: |
public | function |
Returns HTML allowed by this filter's configuration. Overrides FilterInterface:: |
4 |
FilterBase:: |
public | function |
Returns the administrative label for this filter plugin. Overrides FilterInterface:: |
|
FilterBase:: |
public | function |
Returns the processing type of this filter plugin. Overrides FilterInterface:: |
|
FilterBase:: |
public | function |
Prepares the text for processing. Overrides FilterInterface:: |
|
FilterBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
1 |
FilterInterface:: |
constant | HTML tag and attribute restricting filters to prevent XSS attacks. | ||
FilterInterface:: |
constant | Non-HTML markup language filters that generate HTML. | ||
FilterInterface:: |
constant | Irreversible transformation filters. | ||
FilterInterface:: |
constant | Reversible transformation filters. | ||
FlickrFilter:: |
protected | property | Helpers. | |
FlickrFilter:: |
protected | property | Photos. | |
FlickrFilter:: |
protected | property | Photosets. | |
FlickrFilter:: |
private | function | Filter callback for a photo. | |
FlickrFilter:: |
public | function | Filter callback for a user or set. | |
FlickrFilter:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
FlickrFilter:: |
public | function |
Performs the filter processing. Overrides FilterInterface:: |
|
FlickrFilter:: |
public | function |
Generates a filter's settings form. Overrides FilterBase:: |
|
FlickrFilter:: |
public | function |
Generates a filter's tip. Overrides FilterBase:: |
|
FlickrFilter:: |
public | function |
FlickrFilter constructor. Overrides FilterBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
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. |