コード例 #1
0
 public function testAfter()
 {
     $handler = ArrayPosition::after('test2');
     $this->assertEquals(ArrayPosition::AFTER, $handler->position());
     $this->assertEquals('test2', $handler->fieldName());
     $result = $handler->addToArray(array('test1' => 'test', 'test2' => 'test', 'test3' => 'test'), array('after2' => 'value'));
     $this->assertEquals('value', $result['after2']);
     $keys = array_keys($result);
     $this->assertEquals('test1', $keys[0]);
     $this->assertEquals('test2', $keys[1]);
     $this->assertEquals('after2', $keys[2]);
     $this->assertEquals('test3', $keys[3]);
 }
コード例 #2
0
ファイル: Form.php プロジェクト: codefog/contao-haste
 /**
  * Adds a form field from the form generator without trying to convert a DCA configuration.
  *
  * @param string             $strName
  * @param array              $arrDca
  * @param ArrayPosition|null $position
  */
 public function addFieldFromFormGenerator($strName, array $arrDca, ArrayPosition $position = null)
 {
     $this->checkFormFieldNameIsValid($strName);
     if (null === $position) {
         $position = ArrayPosition::last();
     }
     // make sure "name" is set because not all form fields do need it and it would thus overwrite the array indexes
     $strName = $arrDca['name'] ?: 'field_' . $arrDca['id'];
     // Make sure it has a "name" attribute because it is mandatory
     if (!isset($arrDca['name'])) {
         $arrDca['name'] = $strName;
     }
     $this->arrFormFields = $position->addToArray($this->arrFormFields, array($strName => $arrDca));
     $this->intState = self::STATE_DIRTY;
 }