Skip to content

Commit

Permalink
Merge pull request #77 from oveleon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
doishub authored Feb 15, 2023
2 parents 6e25460 + 83111a6 commit 2b4cd96
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"extra":{
"branch-alias": {
"dev-master": "3.0.x-dev"
"dev-master": "3.1.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoComponentStyleManager\\ContaoManager\\Plugin"
}
Expand Down
10 changes: 10 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,13 @@ A special feature is that CSS groups can also be used as template variables via

### Example css group:
![Manage Groups: Image 1](https://www.oveleon.de/share/github-assets/contao-component-style-manager/2.0/groups-edit.png)

# Hide group titles
Since version 3.1, the group titles will be shown above the StyleManager widget

To disabled showing the group title, you can use the following configuration:
```yaml
# config.yaml
contao_component_style_manager:
show_group_title: false
```
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public function getConfigTreeBuilder()
->booleanNode('strict')
->defaultFalse()
->end()
->booleanNode('show_group_title')
->defaultTrue()
->end()
->end()
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ public function load(array $configs, ContainerBuilder $container)

$container->setParameter('contao_component_style_manager.use_bundle_config', $config['use_bundle_config']);
$container->setParameter('contao_component_style_manager.strict', $config['strict']);
$container->setParameter('contao_component_style_manager.show_group_title', $config['show_group_title']);
}
}
4 changes: 4 additions & 0 deletions src/Resources/public/stylemanager.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Resources/public/stylemanager.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Resources/public/stylemanager.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
margin-bottom: 15px;
}

.sm-group-title {
margin-top: 1rem;
padding-bottom: .5rem;
}

.no_styles{
min-height: auto;

Expand Down
51 changes: 50 additions & 1 deletion src/StyleManager/Styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Styles
*/
private ?array $currGroups = null;

/**
* Excluded groups
*/
private ?array $exclGroups = null;

/**
* Initialize the object
*/
Expand Down Expand Up @@ -55,6 +60,11 @@ public function get($identifier, $arrGroups=null): string
{
$collection = array();

if(null !== $this->exclGroups)
{
$this->removeExcludedGroups($arrGroups);
}

foreach ($arrGroups as $groupAlias)
{
if($value = $this->getGroupValue($this->styles[ $identifier ][ $groupAlias ] ?? null))
Expand All @@ -75,7 +85,17 @@ public function get($identifier, $arrGroups=null): string
public function prepare($identifier, $arrGroups=null): Styles
{
$this->currIdentifier = $identifier;
$this->currGroups = $arrGroups;
$this->currGroups = $arrGroups;

return $this;
}

/**
* Exclude css classes
*/
public function exclude(?array $exclGroups=null): Styles
{
$this->exclGroups = $exclGroups;

return $this;
}
Expand Down Expand Up @@ -118,6 +138,11 @@ public function format(string $format, string $method=''): string
}
}

if(null !== $this->exclGroups)
{
$arrValues = array_diff($arrValues, $this->exclGroups);
}

if($arrValues !== null && $jsonValue = json_encode($arrValues))
{
return sprintf($format, $jsonValue);
Expand Down Expand Up @@ -151,6 +176,11 @@ private function getCategoryValues($arrVariables): array
{
$arrValues = [];

if(null !== $this->exclGroups)
{
$this->removeExcludedGroups($arrVariables);
}

foreach ($arrVariables as $alias => $arrVariable)
{
$arrValues[] = $this->getGroupValue($arrVariable);
Expand Down Expand Up @@ -187,4 +217,23 @@ private function parseValueType($strValue)

return $strValue;
}

/**
* Removes excluded groups
*/
private function removeExcludedGroups(array &$currGroups): void
{
foreach ($this->exclGroups as $exclude)
{
if (array_key_exists($exclude, $currGroups))
{
unset($currGroups[$exclude]);
}
// in case the excluded group is a value -> when a group was passed
else if (in_array($exclude, $currGroups))
{
$currGroups = array_diff($currGroups, [$exclude]);
}
}
}
}
21 changes: 16 additions & 5 deletions src/Widget/ComponentStyleSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public function generate()
// Restore default values
$this->varValue = StyleManager::deserializeValues($this->varValue);

// Show group title
$blnShowGroupTitle = System::getContainer()->getParameter('contao_component_style_manager.show_group_title');

// Prepare group fields
foreach($arrObjStyleGroups as $objStyleGroup)
{
Expand Down Expand Up @@ -201,10 +204,11 @@ public function generate()
if(!in_array($collectionAlias, array_keys($arrCollection)))
{
$arrCollection[ $collectionAlias ] = array(
'label' => $arrArchives[ $objStyleGroup->pid ]['title'],
'desc' => $arrArchives[ $objStyleGroup->pid ]['desc'],
'group' => $groupAlias,
'fields' => array()
'label' => $arrArchives[ $objStyleGroup->pid ]['title'],
'desc' => $arrArchives[ $objStyleGroup->pid ]['desc'],
'group' => $groupAlias,
'groupTitle' => $arrArchives[ $objStyleGroup->pid ]['group'] ?? null,
'fields' => array()
);
}

Expand Down Expand Up @@ -250,6 +254,7 @@ public function generate()
{
$arrNavigation = array();
$arrContent = array();
$groupTitle = null;

$i = 0;

Expand Down Expand Up @@ -282,6 +287,12 @@ public function generate()
implode("", $group['fields'])
);

// Set group title if it exists
if ($blnShowGroupTitle && null !== $group['groupTitle'])
{
$groupTitle = '<h4 class="sm-group-title">' . $group['groupTitle'] . '</h4>';
}

$i++;
}

Expand All @@ -291,7 +302,7 @@ public function generate()
$arrNavigation[0] = str_replace("><label", "checked><label", $arrNavigation[0]);
}

$arrSections[] = '<div class="tab-container" id="' . $groupAlias . '">' . implode("", $arrNavigation) . implode("", $arrContent) . '</div>';
$arrSections[] = '<div class="tab-container" id="' . $groupAlias . '">' . $groupTitle . implode("", $arrNavigation) . implode("", $arrContent) . '</div>';
}

return implode("", $arrSections);
Expand Down

0 comments on commit 2b4cd96

Please sign in to comment.