/** * Returns a section instance. * * @param mixed $id * @param \Closure $callback * @return \Illuminate\Support\Collection */ public function section($id, Closure $callback = null) { if (!($section = $this->find($id))) { $this->put($id, $section = new Section($id)); } $section->executeCallback($callback); return $section; }
/** * Returns all the section fieldset fields rules. * * @param \Cartalyst\Settings\Section $section * @return array */ protected function getRules(Section $section) { $rules = []; foreach ($section->all() as $fieldset) { foreach ($fieldset->all() as $field) { if ($_rules = $field->rules) { $rules[$field->id] = $_rules; } } } return $rules; }
/** * Prepares the given section fieldset fields. * * @param \Cartalyst\Settings\Section $section * @return array */ public function prepare(Section $section) { $data = $section->all(); foreach ($data as $fieldset) { foreach ($fieldset->all() as $field) { if (!($config = $field->config)) { throw new InvalidArgumentException("Field [{$field->id}] from section [{$section->id}] is missing the \"config\" attribute!"); } $field->value = $this->request->old($field->id, $this->config->get($config)); } } return $data; }
/** @test */ public function it_can_attach_a_fieldset_to_the_section() { $this->assertCount(0, $this->section); $this->section->attach(new Fieldset('foo')); $this->section->attach(new Fieldset('bar')); $this->section->attach(new Fieldset('baz')); $this->section->attach(new Fieldset('foo')); $this->section->attach(new Section('foo')); $this->assertCount(3, $this->section); }