Commit 50a97935 authored by jurgenhaas's avatar jurgenhaas

Cleanup code

parent 7f557eb2
<?php
/**
* @file
* Contains colorbox_field_formatter.module..
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function colorbox_field_formatter_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the test module.
case 'help.page.colorbox_field_formatter':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Colorbox Field Formatter') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function colorbox_field_formatter_theme() {
$theme = [];
return $theme;
}
......@@ -10,5 +10,7 @@
"issues": "http://drupal.org/project/issues/colorbox_field_formatter",
"source": "http://cgit.drupalcode.org/colorbox_field_formatter"
},
"require": { }
"require": {
"drupal/colorbox": "^1.4"
}
}
<?php
/**
* @file
* Contains \Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter\ColorboxFieldFormatter.
*/
namespace Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter;
use Drupal\colorbox\ColorboxAttachment;
use Drupal\Component\Utility\Html;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Field\Annotation\FieldFormatter;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase;
......@@ -31,8 +24,9 @@ use Drupal\Core\Url;
* )
*/
class ColorboxFieldFormatter extends FormatterBase {
/**
* {@inheritdoc}
* @inheritdoc
*/
public static function defaultSettings() {
$config = \Drupal::config('colorbox.settings');
......@@ -45,11 +39,12 @@ class ColorboxFieldFormatter extends FormatterBase {
'iframe' => 0,
'anchor' => '',
'class' => '',
'rel' => '',
) + parent::defaultSettings();
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form += parent::settingsForm($form, $form_state);
......@@ -126,7 +121,7 @@ class ColorboxFieldFormatter extends FormatterBase {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function settingsSummary() {
$summary = array();
......@@ -159,7 +154,7 @@ class ColorboxFieldFormatter extends FormatterBase {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function viewElements(FieldItemListInterface $items, $langcode) {
$element = array();
......@@ -181,14 +176,13 @@ class ColorboxFieldFormatter extends FormatterBase {
$options['query']['iframe'] = 'true';
}
if (!empty($this->getSetting('anchor'))) {
$options['query']['fragment'] = $this->getSetting('anchor');
$options['fragment'] = $this->getSetting('anchor');
}
if (!empty($this->getSetting('class'))) {
$options['attributes']['class'] = array_merge($options['attributes']['class'], explode(' ', $this->getSetting('class')));
}
$url->setOptions($options);
$ext = $url->isExternal();
$link = Link::fromTextAndUrl($output, $url);
$element[$delta] = $link->toRenderable();
}
......
<?php
/**
* @file
* Contains \Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter\ColorboxFieldFormatterEntityreference.
*/
namespace Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Field\Annotation\FieldFormatter;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -26,7 +19,7 @@ use Drupal\Core\Form\FormStateInterface;
class ColorboxFieldFormatterEntityreference extends ColorboxFieldFormatter {
/**
* {@inheritdoc}
* @inheritdoc
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
......@@ -36,14 +29,14 @@ class ColorboxFieldFormatterEntityreference extends ColorboxFieldFormatter {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
protected function viewValue(FieldItemInterface $item) {
return $item->entity->label();
}
/**
* {@inheritdoc}
* @inheritdoc
*/
protected function getUrl(FieldItemInterface $item) {
return $item->entity->toUrl();
......
<?php
/**
* @file
* Contains \Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter\ColorboxFieldFormatterImage.
*/
namespace Drupal\colorbox_field_formatter\Plugin\Field\FieldFormatter;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Field\Annotation\FieldFormatter;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Form\FormStateInterface;
......@@ -25,7 +18,7 @@ use Drupal\Core\Form\FormStateInterface;
*/
class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
/**
* {@inheritdoc}
* @inheritdoc
*/
public static function defaultSettings() {
return array(
......@@ -34,7 +27,7 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$image_styles = image_style_options(FALSE);
......@@ -52,7 +45,7 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
public function settingsSummary() {
$image_style = $this->getSetting('image_style');
......@@ -73,10 +66,10 @@ class ColorboxFieldFormatterImage extends ColorboxFieldFormatter {
}
/**
* {@inheritdoc}
* @inheritdoc
*/
protected function viewValue(FieldItemInterface $item) {
return $item->view(array('image_style' => $this->getSetting('image_style')));
return $item->view(['settings' => ['image_style' => $this->getSetting('image_style')],]);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment