/** * Get Field instance * * @param string|null field name or null to fetch an array of all * @param bool whether to get the fields array or flattened array * @param bool whether to include tabular form fields in the flattened array * @return Fieldset_Field|false returns false when field wasn't found */ public function field($name = null, $flatten = false, $tabular_form = true) { if ($name === null) { $fields = $this->fields; if ($flatten) { foreach ($this->fieldset_children as $fs_name => $fieldset) { if ($tabular_form or !$fieldset->get_tabular_form()) { \Arr::insert_after_key($fields, $fieldset->field(null, true), $fs_name); } unset($fields[$fs_name]); } } return $fields; } if (!array_key_exists($name, $this->fields)) { if ($flatten) { foreach ($this->fieldset_children as $fieldset) { if (($field = $fieldset->field($name)) !== false) { return $field; } } } return false; } return $this->fields[$name]; }
/** * Tests Arr::insert_after_value() * * @test */ public function test_insert_after_value() { $people = array("Jack", "Jill"); $expected = array("Jack", "Humpty", "Jill"); $output = Arr::insert_after_key($people, "Humpty", "Jack"); $this->assertEquals(true, $output); $this->assertEquals($expected, $people); }
/** * Tests Arr::insert_after_key() * * @test */ public function test_insert_after_key_that_does_not_exist() { $people = array("Jack", "Jill"); $output = Arr::insert_after_key($people, "Humpty", 6); $this->assertFalse($output); }
/** * Insert after a specific key. * * @access public * @return void */ public function insert_after($key, $title, $callback, $ukey = null) { $this->prepare_insert($callback, $ukey); \Arr::insert_after_key($this->properties, $title, $key); $this->properties = \Arr::replace_key($this->properties, array(0 => $ukey)); return $this; }