Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ protected function inject($object)
/**
* Get a parser
*/
public function getParser($content, $offset = 0)
public function getParser($content, $offset = 0, $parser_parent = null)
{
$parserClass = $this->parserClass;

return $this->inject(new $parserClass($content, $this, $offset));
return $this->inject(new $parserClass($content, $this, $offset, $parser_parent));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions Fields/MulticheckboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,12 @@ public function getHtml()
$html = '';

if ($this->checkboxes) {
foreach ($this->checkboxes as $checkbox) {

foreach ($this->checkboxes as $checkboxIndex=>$checkbox) {
$html.= '<div class="'.$this->getAttribute('class').'">';
$html.= '<label>';
$html.= $checkbox->getHtml();
$html.= $this->labels[$checkbox->getName()];
$html.= $this->labels[$this->nameFor($checkboxIndex)];
$html.= '</label>';
$html.= '</div>';
}
Expand Down
2 changes: 1 addition & 1 deletion Fields/Multiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setValues($values, array $files)
$this->forms = array();

$indexes = array();
if ($values) {
if ($values && is_array($values)) {
$indexes = array_keys($values);
} else if ($files) {
$indexes = array_keys($files);
Expand Down
28 changes: 25 additions & 3 deletions Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,28 @@ class Parser extends ParserData
*/
private $offset = 0;

public function __construct($content, $factory = null, $offset = 0)
/**
* Parent parser (for back references from multiples parsers)
*/
private $parser_parent;

/**
* Parser constructor.
* @param $content
* @param null $factory
* @param int $offset
* @param null $parent
*/

public function __construct($content, $factory = null, $offset = 0, $parser_parent = null)
{
if (null === $factory) {
$this->factory = new Factory;
} else {
$this->factory = $factory;
}

$this->parser_parent = $parser_parent;
$this->offset = $offset;
$this->parse($content);
}
Expand Down Expand Up @@ -135,7 +149,13 @@ private function parse($content)
if (!$this->data[$idx-1] instanceof Fields\Select) {
throw new ParserException('<option> should always be in a <select>');
}
$this->sources[$newNode->getSource()] = $newNode;

// target the parent sources area to create an index
if ($this->parser_parent == null) {
$this->sources[$newNode->getSource()] = $newNode;
} else {
$this->parser_parent->sources[$newNode->getSource()] = $newNode;
}
$newNode->setParent($this->data[$idx-1]);
} else {
if ($newNode instanceof Fields\Option) {
Expand All @@ -158,7 +178,9 @@ private function parse($content)
$this->push($newNode);

if ($newNode instanceof Fields\Multiple) {
$parser = $this->factory->getParser($content, $this->offset+1);
// pass in $this for $parser_parent - to make sources available to multiple selects
$parser = $this->factory->getParser($content, $this->offset+1, $this);

$newNode->setParserData($parser);
$this->offset = $parser->getOffset();
}
Expand Down