-
-
Save anonymous/cafe4e57d54da6c369defbe9fc281127 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class structureselectField extends BaseField { | |
public function __construct() { | |
$this->type = 'category'; | |
$this->icon = 'chevron-down'; | |
$this->label = 'category'; | |
$this->options = array(); | |
} | |
public function options() { | |
return FieldOptions::build($this); | |
} | |
public function option($value, $text, $selected = false) { | |
return new Brick('option', $this->i18n($text), array( | |
'value' => $value, | |
'selected' => $selected, | |
)); | |
} | |
public function page() { | |
$output = array(); | |
foreach($this->structure->fields() as $k => $v) { | |
$v['name'] = $k; | |
$v['value'] = '{{' . $k . '}}'; | |
$output[] = $v; | |
} | |
return $page; | |
} | |
public function input() { | |
$select = new Brick('select'); | |
$select->addClass('selectbox'); | |
$select->attr(array( | |
'name' => $this->name(), | |
'id' => $this->id(), | |
'required' => $this->required(), | |
'autocomplete' => $this->autocomplete(), | |
'autofocus' => $this->autofocus(), | |
'readonly' => $this->readonly(), | |
'disabled' => $this->disabled(), | |
)); | |
$select = $select->append($this->option('', '', $this->value() == '')); | |
if($this->readonly()) { | |
$select->attr('tabindex', '-1'); | |
} | |
if($this->field['page']) { | |
$findpage = $this->field['page']; | |
$structure = $this->field['structure']; | |
$course_name = $this->field['name']; | |
$course_code = $this->field['code']; | |
$courses = site()->find($findpage)->$structure()->yaml(); | |
} | |
foreach($courses as $course) { | |
$text = $course[$course_name]; | |
$value = $course[$course_code]; | |
$keys[] = $value; | |
$values[] = $text; | |
} | |
$this->options = array_combine($keys, $values); | |
foreach($this->options() as $value => $text) { | |
$select->append($this->option($value, $text, $this->value() == $value)); | |
} | |
$inner = new Brick('div'); | |
$inner->addClass('selectbox-wrapper'); | |
$inner->append($select); | |
$wrapper = new Brick('div'); | |
$wrapper->addClass('input input-with-selectbox'); | |
$wrapper->append($inner); | |
if($this->readonly()) { | |
$wrapper->addClass('input-is-readonly'); | |
} else { | |
$wrapper->attr('data-focus', 'true'); | |
} | |
return $wrapper; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment