Skip to content

Commit

Permalink
[REMOVAL] Alias select.optgroup and select.option
Browse files Browse the repository at this point in the history
The classes that are currently in TYPO3 CMS were picked
directly from VHS - the VHS classes are turned into aliases
for the TYPO3 CMS classes and marked as deprecated.
  • Loading branch information
NamelessCoder committed Sep 17, 2019
1 parent 78b8ae4 commit c1e5355
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 227 deletions.
29 changes: 3 additions & 26 deletions Classes/ViewHelpers/Form/Select/OptgroupViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,9 @@

/**
* Optgroup ViewHelper to use under vhs:form.select.
*
* @deprecated Will be removed in VHS 6.0; use f:form.select.optgroup instead.
*/
class OptgroupViewHelper extends AbstractTagBasedViewHelper
class OptgroupViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\Select\OptgroupViewHelper
{

/**
* @var string
*/
protected $tagName = 'optgroup';

/**
* Initialize
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('label', 'string', 'Label for this option group');
}

/**
* @return string
*/
public function render()
{
$this->tag->setContent($this->renderChildren());
return $this->tag->render();
}
}
77 changes: 3 additions & 74 deletions Classes/ViewHelpers/Form/Select/OptionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,11 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Vhs\ViewHelpers\Form\SelectViewHelper;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
use TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper;

/**
* Option ViewHelper to use under vhs:form.select.
*
* @deprecated Will be removed in VHS 6.0; use f:form.select.option instead.
*/
class OptionViewHelper extends AbstractFormFieldViewHelper
class OptionViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\Select\OptionViewHelper
{

/**
* @var string
*/
protected $tagName = 'option';

/**
* Initialize
*
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerUniversalTagAttributes();
$this->registerArgument(
'selected',
'boolean',
'Set to TRUE to mark field as selected; otherwise detected from field value'
);
}

/**
* @throws \RuntimeException
* @return string
*/
public function render()
{
if (!$this->renderingContext->getViewHelperVariableContainer()->exists(SelectViewHelper::class, 'options')) {
throw new \RuntimeException(
'Options can only be added inside select tags, optionally inside optgroup tag(s) inside the select tag',
1313937196
);
}
if (true === (boolean) $this->arguments['selected']) {
$selected = 'selected';
} elseif (true === $this->renderingContext->getViewHelperVariableContainer()->exists(SelectViewHelper::class, 'value')) {
$value = $this->renderingContext->getViewHelperVariableContainer()->get(SelectViewHelper::class, 'value');
if (false === is_object($this->arguments['value']) && false === is_array($this->arguments['value'])) {
if (true === is_array($value)) {
$selected = true === in_array($this->arguments['value'], $value) ? 'selected' : '';
} else if (true === ($value instanceof ObjectStorage) && true === is_numeric($this->arguments['value'])) {
// Requires that the option values are UIDs of objects in ObjectStorage
foreach ($value as $object) {
if($object->getUid() === (integer) $this->arguments['value']) {
$selected = 'selected';
break;
}
}
} else {
$selected = (string) $this->arguments['value'] == (string) $value ? 'selected' : '';
}
}
}
$tagContent = $this->renderChildren();
$options = $this->renderingContext->getViewHelperVariableContainer()->get(SelectViewHelper::class, 'options');
$options[$tagContent] = $this->arguments['value'];
$this->renderingContext->getViewHelperVariableContainer()->addOrUpdate(SelectViewHelper::class, 'options', $options);
if (false === empty($selected)) {
$this->tag->addAttribute('selected', 'selected');
} else {
$this->tag->removeAttribute('selected');
}
$this->tag->setContent($tagContent);
if (true === isset($this->arguments['value'])) {
$this->tag->addAttribute('value', $this->arguments['value']);
}
return $this->tag->render();
}
}
41 changes: 0 additions & 41 deletions Tests/Unit/ViewHelpers/Form/Select/OptgroupViewHelperTest.php

This file was deleted.

86 changes: 0 additions & 86 deletions Tests/Unit/ViewHelpers/Form/Select/OptionViewHelperTest.php

This file was deleted.

0 comments on commit c1e5355

Please sign in to comment.