Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Commit

Permalink
Fixes multiple edit error of #6
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffparnitzky committed Dec 10, 2014
1 parent 23aca6b commit 1142c2d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -22,14 +22,14 @@ https://github.com/cliffparnitzky/EfgMemberSelect/issues
Compatibility
-------------

- min. version: Contao 2.9.5
- max. version: Contao 3.1.x
- min. version: Contao 3.0.0
- max. version: Contao 3.4.x


Dependency
----------

- This extension is dependent on the following extensions: [[associategroups]](http://contao.org/de/extension-list/view/associategroups.de.html)
- This extension is dependent on the following extensions: [[associategroups] >= 1.2.1](https://contao.org/de/extension-list/view/associategroups.10020019.de.html), [[efg] >= 2.2.1](https://contao.org/de/extension-list/view/efg.20020019.de.html)


Insert tags
Expand Down
41 changes: 32 additions & 9 deletions system/modules/EfgMemberSelect/FormMemberSelectMenu.php
Expand Up @@ -45,7 +45,8 @@ public function __construct($arrAttributes=false) {
if (!in_array('associategroups', $this->Config->getActiveModules())) {
$this->log('EfgMemberSelect: Extension [associategroups] is necessary!', 'FormMemberSelectMenu generate()', TL_ERROR);
$this->addError('Extension [associategroups] is necessary!');
} else if ($this->efgMemberSelectMembers != null || $this->efgMemberSelectMemberGroups != null) {
} else {
$this->setFieldConfig();
$this->setMemberOptions();
}
}
Expand All @@ -54,6 +55,10 @@ public function __construct($arrAttributes=false) {
* Setting the options array
*/
private function setMemberOptions () {
if (!empty($this->arrOptions)) {
return;
}

$arrValidMembers = $this->getValidMembers();

if ($this->efgMemberSelectIncludeBlankOption) {
Expand Down Expand Up @@ -155,7 +160,7 @@ private function getMemberLabel($arrMember) {
* Overwritten, to set widget template for BE List
*/
public function parse($arrAttributes=false) {
if(TL_MODE == 'BE' && ($this->efgMemberSelectMembers == null || $this->efgMemberSelectMemberGroups)) {
if(TL_MODE == 'BE' && ($this->Input->get('act') == "edit" || $this->Input->get('act') == "editAll")) {
$this->strTemplate = 'be_widget';
}
return parent::parse($arrAttributes);
Expand All @@ -165,7 +170,7 @@ public function parse($arrAttributes=false) {
* Overwritten, to set class attribute
*/
public function generateWithError($blnSwitchOrder=false) {
if(TL_MODE == 'BE' && ($this->efgMemberSelectMembers == null || $this->efgMemberSelectMemberGroups)) {
if(TL_MODE == 'BE') {
$this->strClass .= (strlen($this->strClass) ? ' ' . $this->strClass : '') . 'tl_select';
}
return parent::generateWithError($blnSwitchOrder);
Expand All @@ -176,14 +181,19 @@ public function generateWithError($blnSwitchOrder=false) {
* @return string
*/
public function generate() {
if(TL_MODE == 'BE' && ($this->efgMemberSelectMembers == null || $this->efgMemberSelectMemberGroups)) {
if(TL_MODE == 'BE') {
// there is no config, e.g. in [efg]
$this->setFieldConfig();
$this->setMemberOptions();
if (is_array($this->varValue) && count($this->varValue) == 1) {
$this->varValue = deserialize($this->varValue[0]);
}
}

if (TL_MODE == 'FE') {
$this->varValue = deserialize($this->varValue);
if ($GLOBALS['TL_DCA']['tl_formdata']['fields'][$this->name]['eval']['multiple'] && !is_array($this->varValue)) {
$this->varValue = trimsplit('[,|]', $this->varValue);
}
}
return parent::generate();
}
Expand All @@ -207,26 +217,39 @@ private function isMemberActive($arrMember) {
protected function isValidOption($varInput) {
$this->setFieldConfig();
$arrValidMembers = $this->getValidMembers();

if (count($arrValidMembers) == 0) {
return false;
}

$arrValidValues = array();

foreach ($arrValidMembers as $arrMember) {
$value = $arrMember['id'];
if ($this->efgMemberSelectReturnValue == FormMemberSelectMenu::RETURN_VALUE_NAME)
{
$value = $this->getMemberLabel($arrMember);
}

if ($value == $varInput) {
return true;
if (is_array($varInput)) {
if (in_array($value, $varInput)) {
$arrValidValues[] = $value;
}
} else {
if ($value == $varInput) {
return true;
}
}
}

return false;
return count($arrValidValues) == count($varInput);
}

/**
* There is no config, e.g. in [efg]
*/
private function setFieldConfig() {
$fieldId = $GLOBALS['TL_DCA']['tl_formdata']['fields'][$this->name]['ff_id'];
$fieldId = $GLOBALS['TL_DCA']['tl_formdata']['fields'][$this->strField]['ff_id'];
if ($fieldId > 0)
{
$config = $this->Database->prepare("SELECT * FROM tl_form_field WHERE id = ?")->execute($fieldId);
Expand Down

0 comments on commit 1142c2d

Please sign in to comment.