Skip to content
Snippets Groups Projects

Feature/attributes

Merged Krzysztof Dyszczyk requested to merge feature/attributes into master
1 unresolved thread
2 files
+ 37
7
Compare changes
  • Side-by-side
  • Inline

Files

+ 34
4
@@ -64,13 +64,20 @@ class Notice
* @param string $noticeType Notice type.
* @param bool $dismissible Is dismissible.
* @param int $priority Notice priority.
*/
public function __construct($noticeContent, $noticeType = 'info', $dismissible = false, $priority = 10)
{
* @param array $attributes Attributes.
*/
public function __construct(
$noticeContent,
$noticeType = 'info',
$dismissible = false,
    • btw. najczęściej(nie zawsze) taki parametr bool oznacza, że powinny istnieć klasy, jedna która ma zawsze dissmisible = true i druga która ma zawsze dissmisible = false. Wtedy parametr dissmisible nie jest w ogóle potrzebny bo ta informacja jest zawarta w istocie tego czym są te nowe klasy. np. DissmisibleNotice, NoDismissibleNotice :)

      wtedy PermanentDismissibleNotice extends DissmisibleNotice :)

      By Dyszczo on 2018-10-12T19:32:47 (imported from GitLab)

Please register or sign in to reply
$priority = 10,
$attributes = array()
) {
$this->noticeContent = $noticeContent;
$this->noticeType = $noticeType;
$this->dismissible = $dismissible;
$this->priority = $priority;
$this->attributes = $attributes;
$this->addAction();
}
@@ -176,6 +183,9 @@ class Notice
if ($this->dismissible) {
$notice_class .= ' is-dismissible';
}
if (isset($this->attributes['class'])) {
$notice_class .= ' ' . $this->attributes['class'];
}
return $notice_class;
}
@@ -187,15 +197,35 @@ class Notice
protected function getAttributesAsString()
{
$attribute_string = sprintf('class="%1$s"', esc_attr($this->getNoticeClass()));
foreach ($this->attributes as $attribute_name => $attribute_value) {
if ('class' !== $attribute_name) {
$attribute_string .= sprintf(' %1$s="%2$s"', esc_html($attribute_name), esc_attr($attribute_value));
}
}
return $attribute_string;
}
private function addParagraphToContent()
{
if (0 === strpos($this->noticeContent, '<p>')) {
return false;
}
if (0 === strpos($this->noticeContent, '<div>') || 0 === strpos($this->noticeContent, '<div ')) {
return false;
}
return true;
}
/**
* Show notice;
*/
public function showNotice()
{
echo sprintf('<div %1$s><p>%2$s</p></div>', $this->getAttributesAsString(), $this->noticeContent);
$noticeFormat = '<div %1$s>%2$s</div>';
if ($this->addParagraphToContent()) {
$noticeFormat = '<div %1$s><p>%2$s</p></div>';
}
echo sprintf($noticeFormat, $this->getAttributesAsString(), $this->noticeContent);
}
}
Loading