/**
  * Take a multidimensional array of contents and flattens it.
  * Also make sure FluentHtmlElement objects are cloned and have their parent set to the current object.
  *
  * @param string|Htmlable|FluentHtmlElement|array|Arrayable $html_contents,...
  * @return Collection of contents that are ok to insert into a FluentHtmlElement element
  */
 protected function prepareContentsForInsertion($html_contents)
 {
     return HtmlBuilder::flatten(func_get_args())->map(function ($item) {
         if ($item instanceof FluentHtmlElement) {
             $original_id = $item->getAttribute('id');
             if ($item->hasParent()) {
                 $item = clone $item;
             }
             $item->setParent($this);
             if ($item->getAttribute('id') != $original_id) {
                 $item->withId($original_id);
             }
         }
         return $item;
     })->filter(function ($item) {
         //Filter out empty strings and false values
         return isset($item) and '' !== $item and false !== $item;
     });
 }
Example #2
0
 public function withSelectedOptions($options)
 {
     $this->selected_options = $this->selected_options->merge(HtmlBuilder::flatten(func_get_args()));
     return $this;
 }
 public function testEmptyClassAttribute()
 {
     $this->assertEquals('<br>', HtmlBuilder::buildHtmlElement('br', ['class' => ['a' => false]]));
 }