Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
- Drag-and-drop icons are now longer shown for devices that don’t support pointer events. ([#18067](https://github.com/craftcms/cms/pull/18067))
- The Caches utility now keeps track of which options were previously selected. ([#9447](https://github.com/craftcms/cms/discussions/9447))
- Field layouts can now set editability conditions on custom fields, based on the edited element. ([#18181](https://github.com/craftcms/cms/discussions/18181))
- Element cards can now include fields nested within Content Block fields. ([#18206](https://github.com/craftcms/cms/pull/18206))

### Development
- Reference tags now support fallback values when no attribute is specified. ([#17688](https://github.com/craftcms/cms/pull/17688))
Expand All @@ -61,6 +62,10 @@
### Extensibility
- Subnav items within the global control panel navigation can now have icons. ([#17879](https://github.com/craftcms/cms/pull/17879))
- It’s now possible to modify the template path via `craft\web\View::EVENT_BEFORE_RENDER_TEMPLATE` and `EVENT_BEFORE_RENDER_PAGE_TEMPLATE`. ([#18125](https://github.com/craftcms/cms/issues/18125))
- Added `Craft.BaseElementIndex::asyncSelectDefaultSource()`.
- Added `Craft.BaseElementIndex::asyncSelectSource()`.
- Added `Craft.BaseElementIndex::asyncSelectSourceByKey()`.
- Added `Craft.BaseElementIndex::ensureSourceAttributeInfo()`.
- Added `craft\base\ElementIndex::multiPageSources()`. ([#17779](https://github.com/craftcms/cms/pull/17779))
- Added `craft\base\ElementTrait::$applyingDraft`. ([#18057](https://github.com/craftcms/cms/pull/18057))
- Added `craft\base\ElementTrait::$hasProvisionalChanges`. ([#17915](https://github.com/craftcms/cms/pull/17915))
Expand All @@ -73,6 +78,8 @@
- Added `craft\events\RegisterElementCardAttributesEvent::$fieldLayout`. ([#17920](https://github.com/craftcms/cms/pull/17920))
- Added `craft\fieldlayoutelements\BaseField::EVENT_DEFINE_ACTION_MENU_ITEMS`. ([#18037](https://github.com/craftcms/cms/issues/18037))
- Added `craft\fieldlayoutelements\BaseField::copyAttributeAction()`. ([#18114](https://github.com/craftcms/cms/pull/18114))
- Added `craft\fieldlayoutelements\BaseField::getPreviewOptions()`.
- Added `craft\fieldlayoutelements\BaseField::key()`.
- Added `craft\fieldlayoutelements\CustomField::getElementEditCondition()`.
- Added `craft\fieldlayoutelements\CustomField::setElementEditCondition()`.
- Added `craft\fields\BaseRelationField::VIEW_MODE_CARDS_GRID`.
Expand All @@ -84,9 +91,13 @@
- Added `craft\fields\data\LinkData::getAttributes()`. ([#18184](https://github.com/craftcms/cms/discussions/18184))
- Added `craft\gql\base\ElementArguments::EVENT_DEFINE_ARGUMENTS`. ([#18062](https://github.com/craftcms/cms/discussions/18062))
- Added `craft\helpers\Assets::resolveSubpath()`. ([#18103](https://github.com/craftcms/cms/pull/18103))
- Added `craft\helpers\Cp::cardPreviewOptions()`.
- Added `craft\helpers\ElementHelper::loadProvisionalChanges()`. ([#17915](https://github.com/craftcms/cms/pull/17915))
- Added `craft\helpers\UrlHelper::cpReferralUrl()`.
- Added `craft\models\EntryType::$uiLabelFormat`.
- Added `craft\models\FieldLayout::$thumbFieldKey`.
- Added `craft\models\FieldLayout::getCardBodyHtmlForElement()`.
- Added `craft\models\FieldLayout::getElementByKey()`.
- Added `craft\models\Section::getCpIndexUri()`.
- Added `craft\models\Section::getPage()`.
- Added `craft\services\ElementSources::getFirstPage()`. ([#17779](https://github.com/craftcms/cms/pull/17779))
Expand All @@ -106,10 +117,6 @@
- Added `craft\web\XlsxResponseFormatter`.
- Added `craft\web\YamlResponseFormatter`.
- Added `craft\web\twig\nodes\BaseNode`.
- Added `Craft.BaseElementIndex::asyncSelectDefaultSource()`.
- Added `Craft.BaseElementIndex::asyncSelectSource()`.
- Added `Craft.BaseElementIndex::asyncSelectSourceByKey()`.
- Added `Craft.BaseElementIndex::ensureSourceAttributeInfo()`.
- `craft\base\Element::EVENT_AFTER_MOVE_IN_STRUCTURE` is no longer deprecated.
- `craft\base\Element::EVENT_BEFORE_MOVE_IN_STRUCTURE` is no longer deprecated.
- `craft\base\ElementInterface::afterMoveInStructure()` is no longer deprecated.
Expand All @@ -126,6 +133,8 @@
- `craft\web\Request::accepts()` now accepts wildcard characters (`*`) in the `$contentType` argument, to check for a range of MIME types (e.g. `application/*+json`).
- `craft\web\Request::getAcceptsJson()` now returns `true` for requests with `Content-Type` headers that match `application/*+json`, in addition to `application/json`.
- Checkbox selects can now be configured with a `storageKey` setting.
- Deprecated `craft\fieldlayoutelements\BaseField::$includeInCards`.
- Deprecated `craft\fieldlayoutelements\BaseField::$providesThumbs`.
- Deprecated `craft\fields\BaseRelationField::$showCardsInGrid`.
- Deprecated `craft\fields\Matrix::$showCardsInGrid`.
- Deprecated `craft\helpers\StringHelper::capitalizePersonalName()`. `toPascalCase()` should be used instead.
Expand Down
2 changes: 1 addition & 1 deletion src/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'id' => 'CraftCMS',
'name' => 'Craft CMS',
'version' => '5.8.21',
'schemaVersion' => '5.9.0.3',
'schemaVersion' => '5.9.0.4',
'minVersionRequired' => '4.5.0',
'basePath' => dirname(__DIR__), // Defines the @app alias
'runtimePath' => '@storage/runtime', // Defines the @runtime alias
Expand Down
26 changes: 2 additions & 24 deletions src/controllers/FieldsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,32 +610,10 @@ public function actionRenderCardPreview()
$this->requireAcceptsJson();

$fieldLayoutConfig = $this->request->getRequiredBodyParam('fieldLayoutConfig');
$cardElements = $this->request->getRequiredBodyParam('cardElements');
$showThumb = $this->request->getBodyParam('showThumb', false);
$thumbAlignment = $this->request->getBodyParam('thumbAlignment', false);

if (!isset($fieldLayoutConfig['id'])) {
$fieldLayout = Craft::createObject([
'class' => FieldLayout::class,
...Component::cleanseConfig($fieldLayoutConfig),
]);
$fieldLayout->type = $fieldLayoutConfig['type'];
} else {
$fieldLayout = Craft::$app->getFields()->getLayoutById($fieldLayoutConfig['id']);
}

if (!$fieldLayout) {
throw new BadRequestHttpException('Invalid field layout');
}

$fieldLayout->setCardView(
array_column($cardElements, 'value')
);

$fieldLayout->setCardThumbAlignment($thumbAlignment);
$fieldLayout = Craft::$app->getFields()->createLayout($fieldLayoutConfig);

return $this->asJson([
'previewHtml' => Cp::cardPreviewHtml($fieldLayout, showThumb: $showThumb),
'previewHtml' => Cp::cardPreviewHtml($fieldLayout),
]);
}

Expand Down
24 changes: 24 additions & 0 deletions src/elements/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ protected static function defineActions(string $source): array
];
}

/**
* @inheritdoc
*/
protected static function defineCardAttributes(): array
{
return [
...parent::defineCardAttributes(),
'address' => [
'label' => Craft::t('app', 'Address'),
'placeholder' => fn() => '123 Acme Ln.',
],
];
}

/**
* @inheritdoc
*/
Expand All @@ -126,6 +140,16 @@ protected static function defineTableAttributes(): array
]);
}

/**
* @inheritdoc
*/
protected static function defineDefaultCardAttributes(): array
{
return [
'address',
];
}

/**
* @inheritdoc
*/
Expand Down
53 changes: 44 additions & 9 deletions src/fieldlayoutelements/BaseField.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ abstract class BaseField extends FieldLayoutElement
/**
* @var bool Whether this field should be used to define element thumbnails.
* @since 5.0.0
* @deprecated in 5.9.0
*/
public bool $providesThumbs = false;

/**
* @var bool Whether this field’s contents should be included in element cards.
* @since 5.0.0
* @deprecated in 5.9.0
*/
public bool $includeInCards = false;

Expand All @@ -81,13 +83,34 @@ public function __construct($config = [])
parent::__construct($config);
}

/**
* @inheritdoc
*/
public function fields(): array
{
$fields = parent::fields();
unset($fields['includeInCards'], $fields['providesThumbs']);
return $fields;
}

/**
* Returns the element attribute this field is for.
*
* @return string
*/
abstract public function attribute(): string;

/**
* Returns the key for this field.
*
* @return string
* @since 5.9.0
*/
public function key(): string
{
return $this->attribute();
}

/**
* Returns whether the attribute should be shown for admin users with “Show field handles in edit forms” enabled.
*
Expand Down Expand Up @@ -166,6 +189,26 @@ public function previewable(): bool
return false;
}

/**
* Returns the card preview options supplied by this field.
*
* @return array|null
* @since 5.9.0
*/
public function getPreviewOptions(): ?array
{
if (!$this->previewable()) {
return null;
}

return [
[
'label' => $this->selectorLabel() ?? $this->attribute(),
'value' => $this->attribute(),
],
];
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -244,7 +287,7 @@ protected function selectorAttributes(): array
'mandatory' => $this->mandatory(),
'requirable' => $this->requirable(),
'thumbable' => $this->thumbable(),
'previewable' => $this->previewable(),
'preview-options' => $this->getPreviewOptions(),
],
];
}
Expand Down Expand Up @@ -316,14 +359,6 @@ protected function selectorIndicators(): array
];
}

if ($this->thumbable() && $this->providesThumbs) {
$indicators[] = [
'label' => Craft::t('app', 'This field provides thumbnails for elements'),
'icon' => 'image',
'iconColor' => 'violet',
];
}

return $indicators;
}

Expand Down
53 changes: 53 additions & 0 deletions src/fieldlayoutelements/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use craft\elements\conditions\users\UserCondition;
use craft\elements\User;
use craft\errors\FieldNotFoundException;
use craft\fields\ContentBlock;
use craft\helpers\ArrayHelper;
use craft\helpers\Cp;
use craft\helpers\Html;
Expand Down Expand Up @@ -143,6 +144,22 @@ public function attribute(): string
return $field->handle;
}

/**
* @inheritdoc
*/
public function key(): string
{
try {
$field = $this->getField();
} catch (FieldNotFoundException) {
$field = null;
}

$prefix = $field instanceof ContentBlock ? 'contentBlock' : 'layoutElement';
$uid = $this->uid ?? '{uid}';
return "$prefix:$uid";
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -212,6 +229,42 @@ public function previewable(): bool
return $field instanceof PreviewableFieldInterface;
}

/**
* @inheritdoc
*/
public function getPreviewOptions(): ?array
{
try {
$field = $this->getField();
} catch (FieldNotFoundException) {
return null;
}

if ($field instanceof ContentBlock) {
$options = [];
$label = $this->selectorLabel();
$nestedOptions = Cp::cardPreviewOptions($field->getFieldLayout(), false);
foreach ($nestedOptions as $key => $option) {
$options[] = [
'label' => "$label - {$option['label']}",
'value' => "contentBlock:{uid}.$key",
];
}
return $options;
}

if (!$this->previewable()) {
return null;
}

return [
[
'label' => $this->selectorLabel() ?? $this->attribute(),
'value' => 'layoutElement:{uid}',
],
];
}

/**
* @inheritdoc
*/
Expand Down
5 changes: 0 additions & 5 deletions src/fieldlayoutelements/addresses/AddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
*/
class AddressField extends BaseField
{
/**
* @inheritdoc
*/
public bool $includeInCards = true;

/**
* @inheritdoc
*/
Expand Down
Loading