/** * Handle the command. */ public function handle() { /* * Set the default buttons handler based * on the builder class. Defaulting to * no handler. */ if (!$this->builder->getButtons()) { $buttons = str_replace('TreeBuilder', 'TreeButtons', get_class($this->builder)); if (class_exists($buttons)) { $this->builder->setButtons($buttons . '@handle'); } } /* * Set the default segments handler based * on the builder class. Defaulting to * no handler. */ if (!$this->builder->getSegments()) { $segments = str_replace('TreeBuilder', 'TreeSegments', get_class($this->builder)); if (class_exists($segments)) { $this->builder->setSegments($segments . '@handle'); } } }
/** * Normalize the segment input. * * @param TreeBuilder $builder */ public function normalize(TreeBuilder $builder) { $segments = $builder->getSegments(); foreach ($segments as $key => &$segment) { /** * If the key is non-numerical then * use it as the header and use the * segment as the segment if it's a class. */ if (!is_numeric($key) && !is_array($segment) && class_exists($segment)) { $segment = ['heading' => $key, 'segment' => $segment]; } /** * If the key is non-numerical then * use it as the header and use the * segment as the value. */ if (!is_numeric($key) && !is_array($segment) && !class_exists($segment)) { $segment = ['heading' => $key, 'value' => $segment]; } /** * If the segment is not already an * array then treat it as the value. */ if (!is_array($segment)) { $segment = ['value' => $segment]; } /** * Move all data-* keys * to attributes. */ foreach ($segment as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($segment, 'attributes.' . $attribute, array_pull($segment, $attribute)); } } /** * If no value wrap is set * then use a default. */ array_set($segment, 'wrapper', array_get($segment, 'wrapper', '{value}')); /** * If there is no value then use NULL */ array_set($segment, 'value', array_get($segment, 'value', null)); } $builder->setSegments($segments); }
/** * Build the segments. * * @param TreeBuilder $builder * @param $entry * @return SegmentCollection */ public function build(TreeBuilder $builder, $entry) { $tree = $builder->getTree(); $segments = new SegmentCollection(); if (!$builder->getSegments()) { $builder->setSegments(['entry.edit_link']); } $this->input->read($builder, $entry); foreach ($builder->getSegments() as $segment) { array_set($segment, 'entry', $entry); $segment = $this->evaluator->evaluate($segment, compact('entry', 'tree')); if (array_get($segment, 'enabled', null) === false) { continue; } $segment['value'] = $this->value->make($tree, $segment, $entry); $segments->push($this->factory->make($segment)); } return $segments; }
/** * Translate the tree segments. * * @param TreeBuilder $builder */ public function translate(TreeBuilder $builder) { $builder->setSegments($this->translator->translate($builder->getSegments())); }
/** * Parse the segments. * * @param TreeBuilder $builder */ public function parse(TreeBuilder $builder) { $builder->setSegments($this->parser->parse($builder->getSegments())); }