Skip to content

Commit

Permalink
Added support for groups, closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
ausi committed Jul 24, 2014
1 parent ffdc6b2 commit 6be51a7
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 11 deletions.
25 changes: 22 additions & 3 deletions assets/css/be_main.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
fieldset.collapsed fieldset,
fieldset.collapsed p.rsce_list_description {
fieldset.collapsed p.rsce_list_description,
fieldset.collapsed p.rsce_group_description {
display: none !important;
}
fieldset.rsce_group_no_legend {
padding-top: 0;
border-top: 0;
}
fieldset.rsce_group_no_legend:last-of-type {
padding-bottom: 0
}
.rsce_list_item fieldset.rsce_list,
.rsce_list_item fieldset.rsce_group {
margin: 0;
}
.rsce_list_item fieldset.rsce_group:last-of-type:not(.collapsed) {
padding-bottom: 0;
}
fieldset.rsce_list {
position: relative;
margin-top: 26px;
padding-right: 10px;
padding-bottom: 0;
}
.rsce_list_inner {
margin-bottom: -12px;
}
p.rsce_list_description {
margin: 5px 10px 10px;
}
p.rsce_group_description {
margin: 5px 0;
}
.rsce_list_item {
position: relative;
display: inline-block;
Expand Down
2 changes: 2 additions & 0 deletions config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
'MadeYourDay\\Contao\\Widget\\ListStop' => 'system/modules/rocksolid-custom-elements/src/MadeYourDay/Contao/Widget/ListStop.php',
'MadeYourDay\\Contao\\Widget\\ListItemStart' => 'system/modules/rocksolid-custom-elements/src/MadeYourDay/Contao/Widget/ListItemStart.php',
'MadeYourDay\\Contao\\Widget\\ListItemStop' => 'system/modules/rocksolid-custom-elements/src/MadeYourDay/Contao/Widget/ListItemStop.php',
'MadeYourDay\\Contao\\Widget\\GroupStart' => 'system/modules/rocksolid-custom-elements/src/MadeYourDay/Contao/Widget/GroupStart.php',
'MadeYourDay\\Contao\\Widget\\Hidden' => 'system/modules/rocksolid-custom-elements/src/MadeYourDay/Contao/Widget/Hidden.php',
));

TemplateLoader::addFiles(array(
'be_rsce_list' => 'system/modules/rocksolid-custom-elements/templates',
'be_rsce_group' => 'system/modules/rocksolid-custom-elements/templates',
'be_rsce_hidden' => 'system/modules/rocksolid-custom-elements/templates',
'be_rsce_convert' => 'system/modules/rocksolid-custom-elements/templates',
));
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$GLOBALS['BE_FFL']['rsce_list_stop'] = 'MadeYourDay\\Contao\\Widget\\ListStop';
$GLOBALS['BE_FFL']['rsce_list_item_start'] = 'MadeYourDay\\Contao\\Widget\\ListItemStart';
$GLOBALS['BE_FFL']['rsce_list_item_stop'] = 'MadeYourDay\\Contao\\Widget\\ListItemStop';
$GLOBALS['BE_FFL']['rsce_group_start'] = 'MadeYourDay\\Contao\\Widget\\GroupStart';
$GLOBALS['BE_FFL']['rsce_list_hidden'] = 'MadeYourDay\\Contao\\Widget\\Hidden';

$GLOBALS['TL_MAINTENANCE'][] = 'MadeYourDay\\Contao\\CustomElementsConvert';
Expand Down
37 changes: 34 additions & 3 deletions src/MadeYourDay/Contao/CustomElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ protected function createDca($dc, $type, $createFromPost = false, $tmpField = nu
*/
protected function createDcaItem($fieldPrefix, $fieldName, $fieldConfig, &$paletteFields, $dc, $createFromPost)
{
if (!is_string($fieldConfig) && !is_array($fieldConfig)) {
throw new \Exception('Field config must be of type array or string.');
}
if (strpos($fieldName, '__') !== false) {
throw new \Exception('Field name must not include "__" (' . $this->getDcaFieldValue($dc, 'type') . ': ' . $fieldName . ').');
}
Expand All @@ -446,6 +449,17 @@ protected function createDcaItem($fieldPrefix, $fieldName, $fieldConfig, &$palet
throw new \Exception('Field name must not start or end with "_" (' . $this->getDcaFieldValue($dc, 'type') . ': ' . $fieldName . ').');
}

if (!is_string($fieldName)) {
$fieldName = 'unnamed_' . $fieldName;
}

if (is_string($fieldConfig)) {
$fieldConfig = array(
'inputType' => 'group',
'label' => array($fieldConfig, ''),
);
}

if (isset($fieldConfig['label'])) {
$fieldConfig['label'] = static::getLabelTranslated($fieldConfig['label']);
}
Expand All @@ -464,7 +478,7 @@ protected function createDcaItem($fieldPrefix, $fieldName, $fieldConfig, &$palet

$hasFields = false;
foreach ($fieldConfig['fields'] as $fieldConfig2) {
if ($fieldConfig2['inputType'] !== 'list') {
if (isset($fieldConfig2['inputType']) && $fieldConfig2['inputType'] !== 'list') {
$hasFields = true;
}
}
Expand Down Expand Up @@ -543,6 +557,14 @@ protected function createDcaItem($fieldPrefix, $fieldName, $fieldConfig, &$palet

}

}
else if ($fieldConfig['inputType'] === 'group') {

$fieldConfig['inputType'] = 'rsce_group_start';

$GLOBALS['TL_DCA'][$dc->table]['fields'][$fieldPrefix . $fieldName] = $fieldConfig;
$paletteFields[] = $fieldPrefix . $fieldName;

}
else {

Expand Down Expand Up @@ -790,8 +812,17 @@ protected static function generatePalette($table, array $paletteFields = array()
}
}

$palette .= ';{rsce_legend},';
$palette .= implode(',', $paletteFields);
if (
isset($paletteFields[0])
&& $paletteFields[0] !== 'rsce_data'
&& isset($GLOBALS['TL_DCA'][$table]['fields'][$paletteFields[0]]['inputType'])
&& $GLOBALS['TL_DCA'][$table]['fields'][$paletteFields[0]]['inputType'] !== 'rsce_group_start'
&& $GLOBALS['TL_DCA'][$table]['fields'][$paletteFields[0]]['inputType'] !== 'rsce_list_start'
) {
$palette .= ';{rsce_legend}';
}

$palette .= ',' . implode(',', $paletteFields);

if ($table === 'tl_content' && in_array('image', $standardFields)) {
$palette .= ';{image_legend},addImage';
Expand Down
51 changes: 51 additions & 0 deletions src/MadeYourDay/Contao/Widget/GroupStart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/*
* Copyright MADE/YOUR/DAY OG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace MadeYourDay\Contao\Widget;

/**
* Group start widget
*
* @author Martin Auswöger <[email protected]>
*/
class GroupStart extends \Widget
{
/**
* @var boolean Submit user input
*/
protected $blnSubmitInput = false;

/**
* @var string Template
*/
protected $strTemplate = 'be_rsce_group';

/**
* Generate the widget and return it as string
*
* @return string
*/
public function generate()
{
$this->loadLanguageFile('rocksolid_custom_elements');

$fs = $this->Session->get('fieldset_states');

return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="tl_box rsce_group' . ((!isset($fs[$this->strTable][$this->strId]) || $fs[$this->strTable][$this->strId]) ? '' : ' collapsed') . '"'
. '>'
. '<legend'
. ' onclick="AjaxRequest.toggleFieldset(this, &quot;' . $this->strId . '&quot;, &quot;' . $this->strTable . '&quot;)"'
. '>' . $this->strLabel
. '</legend>'
. ($this->description ? '<p class="rsce_group_description">' . $this->description . '</p>' : '');
}
}
3 changes: 2 additions & 1 deletion src/MadeYourDay/Contao/Widget/ListItemStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function generate()
. (empty($this->arrConfiguration['tl_class']) ? '' : ' ' . $this->arrConfiguration['tl_class'])
. '" data-rsce-name="' . $fieldName . '">'
. ($this->strLabel ? '<div class="rsce_list_item_title" data-rsce-label="' . $this->arrConfiguration['label_template'] . '">' . $this->strLabel . '</div>' : '')
. $toolbar;
. $toolbar
. '<fieldset class="tl_box rsce_group rsce_group_no_legend">';
}
}
2 changes: 1 addition & 1 deletion src/MadeYourDay/Contao/Widget/ListItemStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class ListItemStop extends \Widget
*/
public function generate()
{
return '</div>';
return '</fieldset></div>';
}
}
3 changes: 2 additions & 1 deletion src/MadeYourDay/Contao/Widget/ListStart.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public function generate()

$fs = $this->Session->get('fieldset_states');

return '<div class="clear"></div>'
return '</fieldset>'
. '<div class="clear"></div>'
. '<fieldset'
. ' id="pal_' . $this->strId . '"'
. ' class="tl_box rsce_list' . ((!isset($fs[$this->strTable][$this->strId]) || $fs[$this->strTable][$this->strId]) ? '' : ' collapsed') . '"'
Expand Down
3 changes: 1 addition & 2 deletions src/MadeYourDay/Contao/Widget/ListStop.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class ListStop extends \Widget
*/
public function generate()
{
return '</fieldset>'
. '<script>'
return '<script>'
. 'rsceInitList(\'pal_' . substr($this->strId, 0, -5) . '_start\');'
. '</script>';
}
Expand Down
5 changes: 5 additions & 0 deletions templates/be_rsce_group.html5
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php /* closing the parent div element to make nested elements possible */ ?>
</div>
<?php echo $this->generate() ?>
<?php /* starting a div element to keep the correct element structure */ ?>
<div style="display: none">

0 comments on commit 6be51a7

Please sign in to comment.