Skip to content

Commit

Permalink
support disabled attribute, respect getAttributesFromDca hook
Browse files Browse the repository at this point in the history
  • Loading branch information
koertho committed Nov 6, 2020
1 parent 0cfd849 commit b16d66c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.12.0] - 2020-11-06
- added support for disabled attribute
- respect values added or changed in getAttributesFromDca hook

## [2.11.1] - 2020-10-22
- fixed tinyMce path for contao 4.4

Expand Down
12 changes: 8 additions & 4 deletions src/Resources/views/multi_column_editor_default.html.twig
Expand Up @@ -8,10 +8,14 @@
</div>
{% endif %}

{% if(rows|length < 1 ) %}
<a href="{{ ajaxAddUrl }}" class="add first{% if isBackend %} tl_submit{% endif %}" title="{{ 'huh.multicolumneditor.add.default'|trans }}">
<span>{{ 'huh.multicolumneditor.add.default'|trans }}</span>
</a>
{% if(rows|length < 1) %}
{% if disableAdd|default(false) %}
<button class="add first{% if isBackend %} tl_submit{% endif %}" disabled><span>{{ 'huh.multicolumneditor.add.default'|trans }}</span></button>
{% else %}
<a href="{{ ajaxAddUrl }}" class="add first{% if isBackend %} tl_submit{% endif %}" title="{{ 'huh.multicolumneditor.add.default'|trans }}">
<span>{{ 'huh.multicolumneditor.add.default'|trans }}</span>
</a>
{% endif%}
{% else %}
<div class="rows{{ legend|default() ? ' grouped'}}{{ sortable|default() ? ' sortable' }}">
{% for iterator, row in groupRows %}
Expand Down
21 changes: 20 additions & 1 deletion src/Widget/MultiColumnEditor.php
Expand Up @@ -69,7 +69,7 @@ public function __construct($arrData)
parent::__construct($arrData);

Controller::loadDataContainer($this->strTable);
$this->arrDca = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiColumnEditor'];
$this->arrDca = array_merge($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['multiColumnEditor'], $arrData['multiColumnEditor']);
$this->editorTemplate = $this->arrDca['editorTemplate'] ?? $this->editorTemplate;
$this->container = System::getContainer();

Expand Down Expand Up @@ -165,6 +165,11 @@ public function generateEditorForm(): string

$data['mceErrors'] = $this->arrErrors;

if ($this->getAttribute('disabled')) {
$data['disabled'] = true;
$data['sortable'] = false;
}

return $this->container->get('twig')->render(
$this->container->get('huh.utils.template')->getTemplate($this->getEditorTemplate()),
$data
Expand All @@ -174,6 +179,11 @@ public function generateEditorForm(): string
public function getDisableAdd(array $data): bool
{
$disable = false;

if ($this->getAttribute('disabled')) {
return true;
}

$count = \count($data['rows']);

if ($data['maxRowCount'] && $data['maxRowCount'] <= ($count)) {
Expand All @@ -186,6 +196,11 @@ public function getDisableAdd(array $data): bool
public function getDisableRemove(array $data): bool
{
$disable = false;

if ($this->getAttribute('disabled')) {
return true;
}

$count = \count($data['rows']);

if ($data['minRowCount'] && $data['minRowCount'] >= ($count)) {
Expand Down Expand Up @@ -332,6 +347,10 @@ public function generateRows(): array
$id = $this->strName.'_'.$i.'_'.$field;
$name = $this->strName.'['.$i.']['.$field.']';
$value = $existing[$field];

if ($this->getAttribute('disabled')) {
$config['eval']['disabled'] = true;
}
/** @var Widget $objWidget */
if (null === ($objWidget = $this->container->get('huh.utils.form')->getWidgetFromAttributes($name,
$config, $value, $name, $this->strTable, $this->dataContainer, TL_MODE))) {
Expand Down

0 comments on commit b16d66c

Please sign in to comment.