Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a global field chip to the top of FLD field setting slideouts #15619

Merged
merged 1 commit into from
Aug 29, 2024
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
45 changes: 44 additions & 1 deletion src/base/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.0.0
*/
abstract class Field extends SavableComponent implements FieldInterface
abstract class Field extends SavableComponent implements FieldInterface, Iconic, Actionable
{
use FieldTrait;

Expand Down Expand Up @@ -510,6 +510,14 @@ public function getHandle(): ?string
return $this->handle;
}

/**
* @inheritdoc
*/
public function getIcon(): ?string
{
return static::icon();
}

/**
* @inheritdoc
*/
Expand All @@ -518,6 +526,41 @@ public function getCpEditUrl(): ?string
return $this->id ? UrlHelper::cpUrl("settings/fields/edit/$this->id") : null;
}

/**
* @inheritdoc
*/
public function getActionMenuItems(): array
{
$items = [];

if (
$this->id &&
Craft::$app->getUser()->getIsAdmin() &&
Craft::$app->getConfig()->getGeneral()->allowAdminChanges
) {
$editId = sprintf('action-edit-%s', mt_rand());
$items[] = [
'id' => $editId,
'icon' => 'edit',
'label' => Craft::t('app', 'Edit'),
];

$view = Craft::$app->getView();
$view->registerJsWithVars(fn($id, $params) => <<<JS
$('#' + $id).on('click', () => {
new Craft.CpScreenSlideout('fields/edit-field', {
params: $params,
});
});
JS, [
$view->namespaceInputId($editId),
['fieldId' => $this->id],
]);
}

return $items;
}

/**
* @inheritdoc
*/
Expand Down
25 changes: 24 additions & 1 deletion src/templates/_includes/forms/fld/custom-field-settings.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
{% extends '_includes/forms/fld/field-settings.twig' %}
{% import '_includes/forms' as forms %}

{% set originalField = craft.app.fields.getFieldByUid(field.getField().uid) %}

{% block fieldSettings %}
{% if originalField %}
{% set fieldChipId = "chip#{random()}" %}
<div class="pane no-border p-m">
{{ chip(originalField, {
id: fieldChipId,
class: 'hairline',
showActionMenu: true,
showHandle: true,
}) }}
</div>

{% js %}
(() => {
const $chip = $('#{{ fieldChipId|namespaceInputId }}');
$chip.on('dblclick taphold', (ev) => {
$chip.find('.btn').data('disclosureMenu').$container.find('[data-edit-action]').click();
});
})();
{% endjs %}
{% endif %}

{{ block('labelField') }}

{{ forms.textField({
Expand All @@ -18,7 +41,7 @@
required: true,
data: {
'error-key': 'handle'
}
},
}) }}

{{ block('instructionsField') }}
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/cp.css.map

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions src/web/assets/cp/src/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,34 @@ fieldset:last-child,
margin-block: var(--xl) !important;
}

.p-0 {
padding: 0 !important;
}

.p-2xs {
padding: var(--2xs) !important;
}

.p-xs {
padding: var(--xs) !important;
}

.p-s {
padding: var(--s) !important;
}

.p-m {
padding: var(--m) !important;
}

.p-l {
padding: var(--l) !important;
}

.p-xl {
padding: var(--xl) !important;
}

.pt-0 {
padding-block-start: 0 !important;
}
Expand Down Expand Up @@ -3301,6 +3329,11 @@ table {
.card {
color: var(--custom-text-color, var(--text-color));
background-color: var(--custom-bg-color, var(--gray-050));

&.hairline {
border: 1px solid var(--medium-hairline-color);
background-color: transparent;
}
}

/* chips */
Expand Down Expand Up @@ -5313,6 +5346,7 @@ table.data tbody tr:not(.disabled).active-drop-target {
box-sizing: border-box;

.pane &,
.slideout &,
#content & {
background-color: var(--gray-050);
border: 1px solid var(--hairline-color);
Expand Down
Loading