Example #1
0
 /**
  * Sets a form container.
  *
  * Either pass in an object of type \Core\Form\Container or provide a $spec array.
  * Only instances of \Core\Form\Container which have a label are allowed.
  *
  * @see \Core\Form\Container::setForm
  *
  * @param string                            $key
  * @param array|string|\Core\Form\Container $spec
  * @param bool                              $enabled
  *
  * @return self
  * @throws \InvalidArgumentException
  */
 public function setForm($key, $spec, $enabled = true)
 {
     if (is_object($spec)) {
         if (!$spec instanceof Container) {
             throw new \InvalidArgumentException('Tab container must be of the type \\Core\\Form\\Container');
         }
         if (!$spec->getLabel()) {
             throw new \InvalidArgumentException('Container instances must have a label.');
         }
     }
     if (is_array($spec)) {
         if (!isset($spec['type'])) {
             $spec['type'] = 'Core/Container';
         }
         /*
          * For convenience, forms may be specified outside the options array.
          * But in order to be passed through to the form element manager,
          * we must move it to the options.
          */
         if (!isset($spec['options']['forms']) && isset($spec['forms'])) {
             $spec['options']['forms'] = $spec['forms'];
             unset($spec['forms']);
         }
     }
     return parent::setForm($key, $spec, $enabled);
 }
Example #2
0
 public function testGetActionFor()
 {
     $this->assertNull($this->target->getActionFor('non-existent'));
     $key = 'name';
     $this->target->setForm($key, []);
     $this->assertSame($this->target->getActionFor($key), sprintf('?form=%s', $key));
 }
 public function propertiesProvider()
 {
     $object = new \stdClass();
     $container = new Container();
     $labeldContainer = new Container();
     $labeldContainer->setLabel('testLabel');
     $topContainer = new Container();
     $topContainer->setForm('child', ['__instance__' => $object])->setLabel('top');
     return [['Headscripts', ['default' => ['/js/jquery.bootstrapwizard.min.js'], 'value' => ['test/scripts']]], ['Form', ['value' => 'test', 'setter_args' => [$object], 'setter_exception' => ['\\InvalidArgumentException', 'Tab container must be of the type']]], ['Form', ['value' => 'test', 'setter_args' => [$container], 'setter_exception' => ['\\InvalidArgumentException', 'Container instances must have a label']]], ['Form', ['value' => 'test', 'setter_args' => [$labeldContainer], 'getter_args' => ['test', true], 'expect' => $labeldContainer]], ['Form', ['value' => 'test', 'setter_args' => ['Test/Container'], 'getter_args' => ['test', false], 'expect' => ['type' => 'Test/Container', 'name' => 'test', 'entity' => '*']]], ['Form', ['value' => 'test', 'setter_args' => [['type' => 'Test/Container']], 'getter_args' => ['test', false], 'expect' => ['type' => 'Test/Container', 'name' => 'test', 'entity' => '*']]], ['Form', ['value' => 'test', 'setter_args' => [[]], 'getter_args' => ['test', false], 'expect' => ['type' => 'Core/Container', 'name' => 'test', 'entity' => '*']]], ['Form', ['value' => 'test', 'setter_args' => [['forms' => []]], 'getter_args' => ['test', false], 'expect' => ['type' => 'Core/Container', 'name' => 'test', 'options' => ['forms' => []], 'entity' => '*']]], ['Form', ['value' => 'test', 'setter_args' => [['__instance__' => $object]], 'getter_args' => ['test'], 'getter_exception' => '\\UnexpectedValueException']], ['Form', ['value' => 'test', 'setter_args' => [['__instance__' => $container]], 'getter_args' => ['test'], 'getter_exception' => '\\UnexpectedValueException']], ['Form', ['value' => 'test', 'setter_args' => [['__instance__' => $labeldContainer]], 'getter_args' => ['test'], 'expect' => $labeldContainer]], ['Form', ['value' => 'test', 'setter_args' => [['__instance__' => $topContainer]], 'getter_args' => ['test.child'], 'expect' => $object]]];
 }