/**
  * Set the element to describe.
  * @param FluentHtmlElement $element that this description should describe
  * @return $this
  */
 public function forElement(FluentHtmlElement $element)
 {
     $this->for_element = $element;
     $element->withAttribute('aria-describedby', function () {
         return $this->willRenderInHtml() ? $this->getId() : null;
     });
     return $this;
 }
Exemple #2
0
 /**
  * @param string|callable|null $html_element_name
  * @param string|Htmlable|array|Arrayable $tag_contents
  * @param array|Arrayable $tag_attributes
  */
 public function __construct($html_element_name = null, $tag_contents = [], $tag_attributes = [])
 {
     parent::__construct();
     $this->withHtmlElementName($html_element_name);
     $this->withContent($tag_contents);
     $this->withAttribute($tag_attributes);
 }
 /**
  * Get the element's id string if set, or generate a new id.
  * @param null $desired_id
  * @return string
  */
 public function getId($desired_id = null)
 {
     return parent::getId($desired_id ?: $this->getName());
 }
 /**
  * Helper assertion to check if FluentHtml html content can be considered equal to expected string
  * @param string $expected
  * @param FluentHtmlElement $e
  * @param string|null $message
  */
 protected static function assertHtmlContentEquals($expected, FluentHtmlElement $e, $message = null)
 {
     $e->withHtmlElementName(null);
     //Removing the tag name makes the element hidden in html
     static::assertEquals(static::comparableHtml($expected), static::comparableHtml($e->branchToHtml()), $message ?: 'FluentHtml contents not matching HTML string');
 }
 /**
  * Set this element's parent element.
  *
  * @param FluentHtmlElement|null $parent
  */
 protected function setParent(FluentHtmlElement $parent = null)
 {
     if (!empty($parent) and $this->hasIdRegistrar()) {
         // Move inserted element's IdRegistrar upwards in the tree if element has one and the tree doesn't
         $parent->idRegistrar($this->idRegistrar());
     }
     $this->parent = $parent;
     if (!empty($parent)) {
         foreach ($this->after_insertion_callbacks as $callback) {
             call_user_func($callback, $this);
         }
     }
 }
 public function __construct()
 {
     parent::__construct();
     $this->withHtmlElementName(function () {
         return $this->isInline() ? 'span' : 'div';
     });
     $this->errors = new Collection();
     $this->warnings = new Collection();
     $this->alignment_elements = [$this->createFluentHtmlElement(function () {
         return $this->isAligned() || $this->isInline() ? 'span' : 'div';
     })->withContent(function () {
         return $this->getLabelElement();
     })->withClass(function () {
         return $this->getAlignmentClasses(1);
     })->onlyDisplayedIfHasContent(), $this->createFluentHtmlElement(function () {
         return $this->isAligned() || $this->isInline() ? 'span' : 'div';
     })->withClass(function () {
         return $this->getAlignmentClasses(2);
     }), function () {
         return $this->isDescriptionPulled() ? null : $this->getDescriptionElement();
     }];
     $this->withContent($this->alignment_elements);
     $this->withClass([$this->form_block_class, $this->form_block_aligned_class => function () {
         return $this->isAligned();
     }, $this->form_block_disabled_class => function () {
         return $this->isDisabled();
     }, $this->form_block_required_class => function () {
         return $this->isRequired();
     }, function () {
         return $this->getStateClass();
     }]);
     $this->withAttribute('disabled', function () {
         return $this->isDisabled() and $this->getHtmlElementName() == 'fieldset';
     });
 }
 /**
  * Overridden to make sure any inserted control blocks and sub-containers are registered with this container
  * @inheritdoc
  */
 protected function prepareContentsForInsertion($html_contents)
 {
     return parent::prepareContentsForInsertion(func_get_args())->each(function ($item) {
         if ($item instanceof AbstractControlBlock) {
             $this->form_block_elements->push($item);
         } elseif ($item instanceof AbstractControlBlockContainer) {
             $this->form_block_container_elements->push($item);
         }
     });
 }
 /**
  * @param string|Htmlable|array|Arrayable|null $html_contents
  */
 public function __construct($html_contents = null)
 {
     parent::__construct();
     $this->onlyDisplayedIfHasContent();
     $this->withContent($html_contents);
 }