-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67f3ed8
commit 300e018
Showing
8 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?php | ||
/** | ||
* @link https://craftcms.com/ | ||
* @copyright Copyright (c) Pixel & Tonic, Inc. | ||
* @license https://craftcms.github.io/license/ | ||
*/ | ||
|
||
namespace craft\fieldlayoutelements; | ||
|
||
use Craft; | ||
use craft\base\ElementInterface; | ||
use craft\helpers\Cp; | ||
use craft\helpers\Html; | ||
use craft\helpers\StringHelper; | ||
use yii\helpers\Markdown as MarkdownHelper; | ||
|
||
/** | ||
* Markdown represents a UI element based on Markdown content can be included in field layouts. | ||
* | ||
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com> | ||
* @since 5.5.0 | ||
*/ | ||
class Markdown extends BaseUiElement | ||
{ | ||
/** | ||
* @var string The Markdown content | ||
*/ | ||
public string $content = ''; | ||
|
||
/** | ||
* @var bool Whether the content should be displayed in a pane. | ||
*/ | ||
public bool $displayInPane = true; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function selectorLabel(): string | ||
{ | ||
return StringHelper::firstLine($this->content) ?: 'Markdown'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function selectorIcon(): ?string | ||
{ | ||
return 'markdown'; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function selectorLabelAttributes(): array | ||
{ | ||
$attr = parent::selectorLabelAttributes(); | ||
if ($this->content) { | ||
$attr['class'][] = 'code'; | ||
} | ||
return $attr; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function hasCustomWidth(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function hasSettings() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function settingsHtml(): ?string | ||
{ | ||
return | ||
Cp::textareaFieldHtml([ | ||
'label' => Craft::t('app', 'Content'), | ||
'class' => ['code', 'nicetext'], | ||
'id' => 'content', | ||
'name' => 'content', | ||
'value' => $this->content, | ||
]) . | ||
Cp::lightswitchFieldHtml([ | ||
'label' => Craft::t('app', 'Display content in a pane'), | ||
'id' => 'display-in-pane', | ||
'name' => 'displayInPane', | ||
'on' => $this->displayInPane, | ||
]); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function formHtml(?ElementInterface $element = null, bool $static = false): ?string | ||
{ | ||
$content = MarkdownHelper::process(Html::encode($this->content)); | ||
if ($this->displayInPane) { | ||
$content = Html::tag('div', $content, [ | ||
'class' => 'pane', | ||
]); | ||
} | ||
return Html::tag('div', $content, $this->containerAttributes($element, $static)); | ||
} | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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