Neos\FluidAdaptor\ViewHelpers\Form\SelectViewHelper::initializeArguments PHP Метод

initializeArguments() публичный Метод

Initialize arguments.
public initializeArguments ( ) : void
Результат void
    public function initializeArguments()
    {
        parent::initializeArguments();
        $this->registerUniversalTagAttributes();
        $this->registerTagAttribute('multiple', 'string', 'if set, multiple select field');
        $this->registerTagAttribute('size', 'string', 'Size of input field');
        $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
        $this->registerArgument('options', 'array', 'Associative array with internal IDs as key, and the values are displayed in the select box', true);
        $this->registerArgument('optionValueField', 'string', 'If specified, will call the appropriate getter on each object to determine the value.');
        $this->registerArgument('optionLabelField', 'string', 'If specified, will call the appropriate getter on each object to determine the label.');
        $this->registerArgument('sortByOptionLabel', 'boolean', 'If true, List will be sorted by label.', false, false);
        $this->registerArgument('selectAllByDefault', 'boolean', 'If specified options are selected if none was set before.', false, false);
        $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this ViewHelper', false, 'f3-form-error');
        $this->registerArgument('translate', 'array', 'Configures translation of ViewHelper output.');
        $this->registerArgument('prependOptionLabel', 'string', 'If specified, will provide an option at first position with the specified label.');
        $this->registerArgument('prependOptionValue', 'string', 'If specified, will provide an option at first position with the specified value. This argument is only respected if prependOptionLabel is set.');
    }

Usage Example

 /**
  * @test
  */
 public function multipleSelectOnDomainObjectsCreatesExpectedOptionsWithoutOptionValueField()
 {
     $mockPersistenceManager = $this->createMock(\Neos\Flow\Persistence\PersistenceManagerInterface::class);
     $mockPersistenceManager->expects($this->any())->method('getIdentifierByObject')->will($this->returnCallback(function ($object) {
         return $object->getId();
     }));
     $this->viewHelper->injectPersistenceManager($mockPersistenceManager);
     $this->tagBuilder = new TagBuilder();
     $this->viewHelper->expects($this->exactly(3))->method('registerFieldNameForFormTokenGeneration')->with('myName[]');
     $user_is = new \Neos\FluidAdaptor\ViewHelpers\Fixtures\UserDomainClass(1, 'Ingmar', 'Schlecht');
     $user_sk = new \Neos\FluidAdaptor\ViewHelpers\Fixtures\UserDomainClass(2, 'Sebastian', 'Kurfuerst');
     $user_rl = new \Neos\FluidAdaptor\ViewHelpers\Fixtures\UserDomainClass(3, 'Robert', 'Lemke');
     $this->arguments['options'] = array($user_is, $user_sk, $user_rl);
     $this->arguments['value'] = array($user_rl, $user_is);
     $this->arguments['optionLabelField'] = 'lastName';
     $this->arguments['name'] = 'myName';
     $this->arguments['multiple'] = 'multiple';
     $this->injectDependenciesIntoViewHelper($this->viewHelper);
     $this->viewHelper->initializeArguments();
     $this->viewHelper->initialize();
     $actual = $this->viewHelper->render();
     $expected = '<select multiple="multiple" name="myName[]">' . '<option value="1" selected="selected">Schlecht</option>' . chr(10) . '<option value="2">Kurfuerst</option>' . chr(10) . '<option value="3" selected="selected">Lemke</option>' . chr(10) . '</select>';
     $this->assertSame($expected, $actual);
 }