Skip to content

Commit

Permalink
Html field layout element
Browse files Browse the repository at this point in the history
Resolves #10714
  • Loading branch information
brandonkelly committed Mar 13, 2022
1 parent 1315634 commit f97c298
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Added `craft\base\Element::notesFieldHtml()`.
- Added `craft\base\Element::statusFieldHtml()`.
- Added `craft\events\DefineAssetThumbUrlEvent`, which replaces `GetAssetThumbUrlEvent` (previously removed).
- Added `craft\fieldlayoutelements\Html`. ([#10714](https://github.com/craftcms/cms/discussions/10714))
- Added `craft\services\Assets::EVENT_DEFINE_THUMB_URL`, which replaces `craft\services\Assets::EVENT_GET_ASSET_THUMB_URL` (previously removed).

### Changed
Expand Down
50 changes: 50 additions & 0 deletions src/fieldlayoutelements/Html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\fieldlayoutelements;

use craft\base\ElementInterface;
use craft\base\FieldLayoutElement;
use craft\helpers\Html as HtmlHelper;
use yii\base\NotSupportedException;

/**
* Html represents a field layout component that displays arbitrary HTML.
*
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.5.0
*/
class Html extends FieldLayoutElement
{
private string $html;

/**
* Constructor
*/
public function __construct(string $html, array $config = [])
{
$this->html = $html;
parent::__construct($config);
}

/**
* @inheritdoc
* @throws NotSupportedException
*/
public function selectorHtml(): string
{
throw new NotSupportedException(sprintf('%s should not be included in user-modifyable field layouts.', __CLASS__));
}

/**
* @inheritdoc
*/
public function formHtml(?ElementInterface $element = null, bool $static = false): ?string
{
return HtmlHelper::tag('div', $this->html);
}
}

0 comments on commit f97c298

Please sign in to comment.