Skip to content

Commit d9fa1ca

Browse files
authored
[6.x] Provide extra values through container and publish form (#14041)
1 parent 8fcb524 commit d9fa1ca

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

resources/js/components/entries/PublishForm.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
:track-dirty-state="trackDirtyState"
8787
:sync-field-confirmation-text="syncFieldConfirmationText"
8888
:remember-tab="!isInline"
89+
:provide="{ isWorkingCopy, revisionsEnabled }"
8990
>
9091
<LivePreview
9192
:enabled="isPreviewing"

resources/js/components/ui/Publish/Container.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ const props = defineProps({
8888
type: Boolean,
8989
default: false,
9090
},
91+
/** Extra values to be provided through the context. */
92+
provide: {
93+
type: Object,
94+
default: () => ({})
95+
},
9196
});
9297
9398
const parentContainer = injectContainerContext(containerContextKey);
@@ -176,6 +181,7 @@ watch(
176181
177182
const avoidTrackingDirtyState = ref(false);
178183
const trackingDirtyState = computed(() => props.trackDirtyState && !avoidTrackingDirtyState.value)
184+
const isDirty = computed(() => Statamic.$dirty.has(props.name));
179185
180186
function dirty() {
181187
if (trackingDirtyState.value) Statamic.$dirty.add(props.name);
@@ -236,7 +242,11 @@ function pushComponent(name, { props }) {
236242
return component;
237243
}
238244
239-
const provided = {
245+
const additionalProvides = Object.fromEntries(
246+
Object.entries(props.provide).map(([key]) => [key, toRef(() => props.provide[key])])
247+
);
248+
249+
const builtInProvides = {
240250
name: toRef(() => props.name),
241251
parentContainer,
242252
blueprint: toRef(() => props.blueprint),
@@ -268,9 +278,20 @@ const provided = {
268278
setRevealerField,
269279
unsetRevealerField,
270280
setHiddenField,
281+
isDirty,
271282
withoutDirtying,
272283
};
273284
285+
if (import.meta.env.DEV) {
286+
for (const key of Object.keys(additionalProvides)) {
287+
if (key in builtInProvides) {
288+
console.warn(`PublishContainer: provide key "${key}" collides with a built-in context key, which takes precedence.`);
289+
}
290+
}
291+
}
292+
293+
const provided = { ...additionalProvides, ...builtInProvides };
294+
274295
provideContainerContext({ ...provided, container: provided });
275296
276297
defineExpose({

0 commit comments

Comments
 (0)