Skip to content

Commit

Permalink
[FEATURE] Add emptyOption property for all relation-type fields
Browse files Browse the repository at this point in the history
Close: #1070
  • Loading branch information
NamelessCoder committed Apr 11, 2016
1 parent c59b3bd commit 27d5d81
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Classes/Form/AbstractRelationFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ abstract class AbstractRelationFormField extends AbstractMultiValueFormField imp
*/
protected $showThumbnails = FALSE;

/**
* If not-FALSE, adds one empty option/value pair to the generated selector
* box and tries to use this property's value (cast to string) as label.
*
* @var boolean|string
*/
protected $emptyOption = FALSE;

/**
* @param string $type
* @return array
Expand Down Expand Up @@ -540,4 +548,20 @@ public function getShowThumbnails() {
return $this->showThumbnails;
}

/**
* @param boolean|string $emptyOption
* @return Select
*/
public function setEmptyOption($emptyOption) {
$this->emptyOption = $emptyOption;
return $this;
}

/**
* @return boolean|string
*/
public function getEmptyOption() {
return $this->emptyOption;
}

}
22 changes: 22 additions & 0 deletions Classes/Form/RelationFieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,26 @@ public function setShowThumbnails($showThumbnails);
*/
public function getShowThumbnails();

/**
* @param boolean|string $emptyOption
* @return Select
*/
public function setEmptyOption($emptyOption);

/**
* @return boolean|string
*/
public function getEmptyOption();

/**
* @return string
*/
public function getOppositeField();

/**
* @param string $oppositeField
* @return RelationFieldInterface
*/
public function setOppositeField($oppositeField);

}
2 changes: 2 additions & 0 deletions Classes/ViewHelpers/Field/AbstractRelationFieldViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function initializeArguments() {
$this->registerArgument('showThumbs', 'boolean', 'If TRUE, adds thumbnail display when editing in BE', FALSE, TRUE);
$this->registerArgument('matchFields', 'array', 'When using manyToMany you can provide an additional array of field=>value pairs that must match in the relation table', FALSE, array());
$this->registerArgument('oppositeField', 'string', 'Name of the opposite field related to a proper mm relation', FALSE, '');
$this->registerArgument('emptyOption', 'mixed', 'If not-FALSE, adds one empty option/value pair to the generated selector box and tries to use this property\'s value (cast to string) as label.', FALSE, FALSE);
}

/**
Expand Down Expand Up @@ -82,6 +83,7 @@ protected static function getPreparedComponent($type, RenderingContextInterface
$component->setShowThumbnails($arguments['showThumbs']);
$component->setMatchFields((array) $arguments['matchFields']);
$component->setOppositeField($arguments['oppositeField']);
$component->setEmptyOption($arguments['emptyOption']);
return $component;
}

Expand Down

0 comments on commit 27d5d81

Please sign in to comment.