Skip to content
Open
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
1 change: 1 addition & 0 deletions resources/js/components/entries/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
:name="publishContainer"
:reference="reference"
:blueprint="fieldset"
:is-creating="isCreating"
v-model="values"
:extra-values="extraValues"
v-model:meta="meta"
Expand Down
2 changes: 2 additions & 0 deletions resources/js/components/fields/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export default {
provide() {
return {
isInsideConfigFields: true,
// Lets config fieldtypes suggest the fields of the blueprint being edited, like the Conditions tab does.
suggestableConditionFieldsProvider: { suggestableFields: () => this.suggestableConditionFields },
updateFieldSettingsValue: this.updateField,
getFieldSettingsValue: this.getFieldValue,
commitParentField: this.commit,
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/globals/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
:name="publishContainer"
:reference="reference"
:blueprint="fieldset"
:is-creating="isCreating"
:as-config="asConfig"
v-model="values"
:meta="meta"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/structures/PageEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ref="container"
:name="publishContainer"
:blueprint="adjustedBlueprint"
:is-creating="creating"
:meta="meta"
:errors="errors"
:origin-values="originValues"
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/terms/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
:name="publishContainer"
:reference="reference"
:blueprint="fieldset"
:is-creating="isCreating"
v-model="values"
:meta="meta"
:origin-values="originValues"
Expand Down
8 changes: 8 additions & 0 deletions resources/js/components/ui/Publish/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const props = defineProps({
/** Reference of the item being edited. eg. entry::the-entry-id */
reference: {
type: String,
},
/** Whether the item is being created, rather than edited. False unless the form says so. */
isCreating: {
type: Boolean,
default: false,
},
/** The blueprint's publish array. */
blueprint: {
Expand Down Expand Up @@ -300,6 +305,7 @@ const builtInProvides = {
name: toRef(() => props.name),
parentContainer,
blueprint: toRef(() => props.blueprint),
isCreating: toRef(() => props.isCreating),
reference: toRef(() => props.reference),
values,
extraValues,
Expand Down Expand Up @@ -353,6 +359,8 @@ onMounted(() => {
Statamic.$events.$emit('publish-container-created', {
name: props.name,
reference: toRef(() => props.reference),
blueprint: toRef(() => props.blueprint),
isCreating: toRef(() => props.isCreating),
site: toRef(() => props.site),
values,
setFieldValue,
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/user-groups/PublishForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function save() {
:blueprint="fieldset"
v-model="values"
:reference="initialReference"
:is-creating="isCreating"
:meta="meta"
:errors="errors"
as-config
Expand Down
1 change: 1 addition & 0 deletions resources/js/components/users/Wizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<ui-publish-container
ref="container"
:blueprint="blueprint"
is-creating
v-model="values"
:meta="meta"
:extra-values="{
Expand Down
43 changes: 43 additions & 0 deletions resources/js/tests/components/Container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ window.Statamic = {
$events: { $emit: () => {} },
};

const noEmit = window.Statamic.$events.$emit;

const Probe = defineComponent({
setup() {
const { direction } = useContentDirection();
Expand All @@ -34,6 +36,7 @@ beforeEach(async () => {

afterEach(() => {
document.documentElement.removeAttribute('dir');
window.Statamic.$events.$emit = noEmit;
});

test('content direction is unaffected by the CP/document direction when the site has an explicit direction', () => {
Expand Down Expand Up @@ -124,3 +127,43 @@ test('setting field meta does not read the rest of the meta', async () => {

expect(reads).toBe(readsAfterMount);
});

function captureEvents() {
const emitted = [];
window.Statamic.$events.$emit = (name, payload) => emitted.push([name, payload]);

return () => emitted.find(([name]) => name === 'publish-container-created')[1];
}

test('the container context and the created event tell whether the item is being created', async () => {
const created = captureEvents();
const blueprint = { tabs: [] };

let context;
mount(Container, {
props: { blueprint, site: 'default', isCreating: true },
slots: {
default: () =>
h(
defineComponent({
setup() {
context = injectContainerContext();
return () => null;
},
}),
),
},
});

expect(context.isCreating.value).toBe(true);
expect(created().isCreating.value).toBe(true);
expect(created().blueprint.value).toEqual(blueprint);
});

test('a container is not being created by default', () => {
const created = captureEvents();

mount(Container, { props: { blueprint: { tabs: [] }, site: 'default' }, slots: { default: () => h('div') } });

expect(created().isCreating.value).toBe(false);
});
Loading