Commit c03f9c70 authored by jurgenhaas's avatar jurgenhaas

Issue #2860432 by jurgenhaas: open custom div in colorbox

parent e07f9759
......@@ -37,6 +37,7 @@ class ColorboxFieldFormatter extends FormatterBase {
'width' => '500',
'height' => '500',
'iframe' => 0,
'inline_selector' => '',
'anchor' => '',
'class' => '',
'rel' => '',
......@@ -54,9 +55,20 @@ class ColorboxFieldFormatter extends FormatterBase {
'#type' => 'select',
'#default_value' => $this->getSetting('style'),
'#options' => $this->getStyles(),
'#attributes' => array(
'class' => array('colorbox-field-formatter-style'),
),
);
$form['link_type'] = array(
$form['link_wrapper'] = array(
'#type' => 'container',
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-style' => array('value' => 'default'),
),
),
);
$form['link_wrapper']['link_type'] = array(
'#title' => $this->t('Link colorbox to'),
'#type' => 'select',
'#default_value' => $this->getSetting('link_type'),
......@@ -65,7 +77,7 @@ class ColorboxFieldFormatter extends FormatterBase {
'class' => array('colorbox-field-formatter-link-type'),
),
);
$form['link'] = array(
$form['link_wrapper']['link'] = array(
'#title' => $this->t('URI'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('link'),
......@@ -76,7 +88,7 @@ class ColorboxFieldFormatter extends FormatterBase {
),
);
if (\Drupal::moduleHandler()->moduleExists('token') && isset($form['#entity_type'])) {
$form['token_help_wrapper'] = array(
$form['link_wrapper']['token_help_wrapper'] = array(
'#type' => 'container',
'#states' => array(
'visible' => array(
......@@ -84,12 +96,22 @@ class ColorboxFieldFormatter extends FormatterBase {
),
),
);
$form['token_help_wrapper']['token_help'] = array(
$form['link_wrapper']['token_help_wrapper']['token_help'] = array(
'#theme' => 'token_tree',
'#token_types' => array('entity' => $form['#entity_type']),
'#global_types' => FALSE,
);
}
$form['inline_selector'] = array(
'#title' => $this->t('Inline selector'),
'#type' => 'textfield',
'#default_value' => $this->getSetting('inline_selector'),
'#states' => array(
'visible' => array(
'select.colorbox-field-formatter-style' => array('value' => 'colorbox-inline'),
),
),
);
$form['width'] = array(
'#title' => $this->t('Width'),
......@@ -135,17 +157,22 @@ class ColorboxFieldFormatter extends FormatterBase {
$styles = $this->getStyles();
$summary[] = $this->t('Style: @style', ['@style' => $styles[$this->getSetting('style')],]);
$types = $this->getLinkTypes();
switch ($this->getSetting('link_type')) {
case 'manual':
$summary[] = $this->t('Link to @link', ['@link' => $this->getSetting('link'),]);
break;
if ($this->getSetting('style') == 'default') {
$types = $this->getLinkTypes();
switch ($this->getSetting('link_type')) {
case 'manual':
$summary[] = $this->t('Link to @link', ['@link' => $this->getSetting('link'),]);
break;
default:
$summary[] = $this->t('Link to @link', ['@link' => $types[$this->getSetting('link_type')],]);
break;
default:
$summary[] = $this->t('Link to @link', ['@link' => $types[$this->getSetting('link_type')],]);
break;
}
}
if ($this->getSetting('style') == 'colorbox-inline') {
$summary[] = $this->t('Inline selector: @selector', ['@selector' => $this->getSetting('inline_selector'),]);
}
$summary[] = $this->t('Width: @width', ['@width' => $this->getSetting('width'),]);
$summary[] = $this->t('Height: @height', ['@height' => $this->getSetting('height'),]);
$summary[] = $this->t('iFrame Mode: @mode', ['@mode' => ($this->getSetting('iframe') ? $this->t('Yes') : $this->t('No')),]);
......@@ -193,6 +220,9 @@ class ColorboxFieldFormatter extends FormatterBase {
if (!empty($this->getSetting('rel'))) {
$options['attributes']['rel'] = $this->getSetting('rel');
}
if ($this->getSetting('style') == 'colorbox-inline') {
$options['attributes']['data-colorbox-inline'] = $this->getSetting('inline_selector');
}
$url->setOptions($options);
$link = Link::fromTextAndUrl($output, $url);
......@@ -255,9 +285,9 @@ class ColorboxFieldFormatter extends FormatterBase {
$styles = array(
'default' => $this->t('Default'),
);
// TODO: Add more styles to the array
$config = \Drupal::config('colorbox.settings');
if (\Drupal::moduleHandler()->moduleExists('colorbox_inline')) {
$styles['colorbox-inline'] = $this->t('Colorbox inline');
}
if (\Drupal::moduleHandler()->moduleExists('colorbox_node')) {
$styles['colorbox-node'] = $this->t('Colorbox node');
}
......
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