Commit 83fa87f8 authored by alexpott's avatar alexpott

Issue #1938910 by JeroenT, Temoor, gnuget, pratik60, dsnopek, Brandonian |...

Issue #1938910 by JeroenT, Temoor, gnuget, pratik60, dsnopek, Brandonian | duellj: Convert image theme tables to table #type.
parent d25e7dda
......@@ -9,71 +9,6 @@
use Drupal\Component\Utility\String;
use Drupal\Core\Render\Element;
/**
* Returns HTML for a listing of the effects within a specific image style.
*
* @param $variables
* An associative array containing:
* - form: A render element representing the form.
*
* @ingroup themeable
*/
function theme_image_style_effects($variables) {
$form = $variables['form'];
$rows = array();
foreach (Element::children($form) as $key) {
$row = array();
$form[$key]['weight']['#attributes']['class'] = array('image-effect-order-weight');
if ($key != 'new') {
$summary = drupal_render($form[$key]['summary']);
$row[] = drupal_render($form[$key]['label']) . (empty($summary) ? '' : ' ' . $summary);
$row[] = drupal_render($form[$key]['weight']);
$row[] = array('data' => $form[$key]['operations']);
}
else {
// Add the row for adding a new image effect.
$cell = '<div class="image-style-new">' . drupal_render($form['new']['new']) . drupal_render($form['new']['add']) . '</div>';
$row[] = SafeMarkup::set($cell);
$row[] = drupal_render($form['new']['weight']);
$row[] = '';
}
$rows[] = array(
'data' => $row,
'class' => array('draggable'),
);
}
$header = array(
t('Effect'),
t('Weight'),
t('Operations'),
);
if (count($rows) == 1 && (!isset($form['new']['#access']) || $form['new']['#access'])) {
array_unshift($rows, array(array(
'data' => t('There are currently no effects in this style. Add one by selecting an option below.'),
'colspan' => 4,
)));
}
$table = array(
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
'#attributes' => array('id' => 'image-style-effects'),
'#tabledrag' => array(
array(
'action' => 'order',
'relationship' => 'sibling',
'group' => 'image-effect-order-weight',
),
),
);
return drupal_render($table);
}
/**
* Prepares variables for image style preview templates.
*
......
......@@ -111,10 +111,6 @@ function image_theme() {
),
// Theme functions in image.admin.inc.
'image_style_effects' => array(
'render element' => 'form',
'file' => 'image.admin.inc',
),
'image_style_preview' => array(
'variables' => array('style' => NULL),
'file' => 'image.admin.inc',
......
......@@ -70,22 +70,54 @@ public function form(array $form, FormStateInterface $form_state) {
// Build the list of existing image effects for this image style.
$form['effects'] = array(
'#theme' => 'image_style_effects',
'#type' => 'table',
'#header' => array(
$this->t('Effect'),
$this->t('Weight'),
$this->t('Operations'),
),
'#tabledrag' => array(
array(
'action' => 'order',
'relationship' => 'sibling',
'group' => 'image-effect-order-weight',
),
),
'#attributes' => array(
'id' => 'image-style-effects',
),
'#empty' => t('There are currently no effects in this style. Add one by selecting an option below.'),
// Render effects below parent elements.
'#weight' => 5,
);
foreach ($this->entity->getEffects() as $effect) {
$key = $effect->getUuid();
$form['effects'][$key]['#attributes']['class'][] = 'draggable';
$form['effects'][$key]['#weight'] = isset($form_state['input']['effects']) ? $form_state['input']['effects'][$key]['weight'] : NULL;
$form['effects'][$key]['label'] = array(
'#markup' => String::checkPlain($effect->label()),
$form['effects'][$key]['effect'] = array(
'#tree' => FALSE,
'data' => array(
'label' => array(
'#markup' => String::checkPlain($effect->label()),
),
),
);
$form['effects'][$key]['summary'] = $effect->getSummary();
$summary = $effect->getSummary();
if (!empty($summary)) {
$summary['#prefix'] = ' ';
$form['effects'][$key]['effect']['data']['summary'] = $summary;
}
$form['effects'][$key]['weight'] = array(
'#type' => 'weight',
'#title' => $this->t('Weight for @title', array('@title' => $effect->label())),
'#title_display' => 'invisible',
'#default_value' => $effect->getWeight(),
'#attributes' => array(
'class' => array('image-effect-order-weight'),
),
);
$links = array();
......@@ -104,17 +136,6 @@ public function form(array $form, FormStateInterface $form_state) {
'#type' => 'operations',
'#links' => $links,
);
$form['effects'][$key]['configure'] = array(
'#type' => 'link',
'#title' => $this->t('Edit'),
'#href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key,
'#access' => $is_configurable,
);
$form['effects'][$key]['remove'] = array(
'#type' => 'link',
'#title' => $this->t('Delete'),
'#href' => 'admin/config/media/image-styles/manage/' . $this->entity->id() . '/effects/' . $key . '/delete',
);
}
// Build the new image effect addition form and add it to the effect list.
......@@ -129,25 +150,39 @@ public function form(array $form, FormStateInterface $form_state) {
$form['effects']['new'] = array(
'#tree' => FALSE,
'#weight' => isset($form_state['input']['weight']) ? $form_state['input']['weight'] : NULL,
'#attributes' => array('class' => array('draggable')),
);
$form['effects']['new']['new'] = array(
'#type' => 'select',
'#title' => $this->t('Effect'),
'#title_display' => 'invisible',
'#options' => $new_effect_options,
'#empty_option' => $this->t('Select a new effect'),
$form['effects']['new']['effect'] = array(
'data' => array(
'new' => array(
'#type' => 'select',
'#title' => $this->t('Effect'),
'#title_display' => 'invisible',
'#options' => $new_effect_options,
'#empty_option' => $this->t('Select a new effect'),
),
array(
'add' => array(
'#type' => 'submit',
'#value' => $this->t('Add'),
'#validate' => array(array($this, 'effectValidate')),
'#submit' => array(array($this, 'effectSave')),
),
),
),
'#prefix' => '<div class="image-style-new">',
'#suffix' => '</div>',
);
$form['effects']['new']['weight'] = array(
'#type' => 'weight',
'#title' => $this->t('Weight for new effect'),
'#title_display' => 'invisible',
'#default_value' => count($form['effects']) - 1,
'#default_value' => count($this->entity->getEffects()) + 1,
'#attributes' => array('class' => array('image-effect-order-weight')),
);
$form['effects']['new']['add'] = array(
'#type' => 'submit',
'#value' => $this->t('Add'),
'#validate' => array(array($this, 'effectValidate')),
'#submit' => array(array($this, 'effectSave')),
$form['effects']['new']['operations'] = array(
'data' => array(),
);
return parent::form($form, $form_state);
......
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