Hi,
I am using a Uniform action to create a page using data from a submitted form. It looks like this:
class ApplyAction extends Action
{
public function perform() {
// Data from the form
$name = $this->form->data('schoolname');
$email = $this->form->data('email');
$settingType = $this->form->data('settingtype');
$contactFirstName = $this->form->data('contactfirstname');
$contactSurname = $this->form->data('contactsurname');
$contactRole = $this->form->data('contactrole');
$settingDirectLine = $this->form->data('settingdirectline');
$mobileNumber = $this->form->data('mobilenumber');
if($settingType == 'university'):
$parent = page('universities');
else:
$parent = page($settingType);
endif;
// Create a unique slug
$slug = 'setting-' . Str::slug($name) . '-' . time();
// Generate a page for them
try {
kirby()->impersonate('kirby');
$page = Page::create([
'slug' => $slug,
'template' => 'setting',
'parent' => $parent,
'content' => [
'title' => $name,
'settingType' => $settingType,
'contactFirstName' => $contactFirstName,
'contactSurname' => $contactSurname,
'contactRole' => $contactRole,
'settingDirectLine' => $settingDirectLine,
'mobileNumber' => $mobileNumber,
'contactEmail' => $email,
'mentor' => [],
]
]);
$page->changeStatus("unlisted");
kirby()->impersonate(null);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
}
Which is working great. I now need to copy a page, and its children and files, to be a child of this newly created page. The page I want to copy has the slug questionnaires, and is a child of the $parent page in the action above.
I can’t get this to work at all. I have tried $page->copy() (which isn’t documented in 4.8 but seems to be an action), and also a duplicate and move, but am not getting any results. If anyone could offer any pointers that would be super.
Can the parent receive pages? Please post the blueprints of the intended targets.
The created page (and target for the copy) blueprint is setting.yml. Copied below:
setting.yml
title: Setting
options:
changeSlug: false
duplicate: false
preview: false
delete:
admin: true
mentor: false
changeTitle:
admin: true
mentor: false
status:
unlisted: Published
tabs:
informationTab:
label: Information
icon: user
sections:
information:
type: fields
fields:
informationHeadline:
label: Information
type: headline
help: This is the general information provided by the setting, and as such shouldn't need updating
numbered: false
settingType:
type: select
label: Setting type
default: primary
empty: false
width: 1/3
options:
primary: Primary
secondary: Secondary
university: University
alternative: Alternative provision
settingDirectLine:
width: 1/3
type: tel
label: Setting direct line
mobileNumber:
width: 1/3
type: tel
label: Mobile number
contactFirstName:
width: 1/4
type: text
label: Contact first name
contactSurname:
width: 1/4
type: text
label: Contact surname
contactEmail:
width: 1/4
type: email
label: Contact email
contactRole:
width: 1/4
type: text
label: Contact role
mentor:
type: users
multiple: false
query: kirby.users.filterBy('role','in', ['mentor','admin'])
empty: No mentor selected
image: false
default: false
signupLinkHeadline:
label: Signup link
help: Send the link below to the setting - this links to a signup form to allow staff members to register for an account on the site, connected to this setting
type: headline
signupLink:
type: info
label: false
text: |
{{site.url}}/access?id={{ page.uuid.id }}
filesTab:
label: Files
icon: file
sections:
headline:
type: fields
fields:
filesHeadline:
label: Files
type: headline
help: Use this section to add files for this setting to have access to on their dashboard. These will appear in addition to the master files set <a href="/panel/pages/{{ page.parent.slug }}?tab=masterFiles">here</a>
numbered: false
settingFiles:
type: files
label: Setting files
empty: No files added yet
template: setting-file
text: "{{file.friendlyName.or(file.filename)}}"
info: "{{file.niceSize}}"
help: Add files here. Click on the file to add a "friendly name" to be more readable for users. If this isn't added the filename itself will be used.
image:
back: white
progressTab:
label: Tasks & progress
icon: check
sections:
progress:
type: fields
fields:
progressHeadline:
label: Tasks & Progress
type: headline
help: This is the setting's progress through the Toolkit. Here you can control the tasks the setting has to complete, and also their progress through them. This is then reflected on the setting's dashboard and section pages.
numbered: false
showBadge:
label: Show accreditation badge to download
help: If this is toggled on, the setting will see the option to download the accreditation badge on their dashboard. This should only be done upon successful completion of the toolkit
type: toggle
width: 1/2
text:
- "No"
- "Yes"
suggestATask:
type: toggle
label: Suggest a next task
help: When this is switched on, you can choose the "Next task" that is shown to this setting in the dashboard. Do this using the toggles next to the tasks below. Please note, if more than one is suggested then the one earliest in the framework is used.
width: 1/2
text:
- "No"
- "Yes"
progressStats:
type: stats
label: Progress statistics
size: huge
reports:
- label: tasks completed
value: "{{ page.taskStats.approvedCount }}"
- label: task(s) pending review
value: "{{ page.taskStats.pending }}"
primary:
when:
settingType: primary
type: fields
fields:
primaryProjectDeliveryTeamHeadline:
type: headline
label: Project delivery team
primaryProjectDeliveryTeamLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
primaryProjectDeliveryTeamPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
primaryProjectDeliveryTeamTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
primaryInvolvingSettingStaffHeadline:
type: headline
label: Involving setting staff
primaryInvolvingSettingStaffLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
primaryInvolvingSettingStaffPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
primaryInvolvingSettingStaffTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
primaryWorkingWithChildrenHeadline:
type: headline
label: Working with children & young people
primaryWorkingWithChildrenLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
primaryWorkingWithChildrenPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
primaryWorkingWithChildrenTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
primaryInvolvingFamiliesAndCommunitiesHeadline:
type: headline
label: Involving families & communities
primaryInvolvingFamiliesAndCommunitiesLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
primaryInvolvingFamiliesAndCommunitiesPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
primaryInvolvingFamiliesAndCommunitiesTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
primaryPositiveSettingCultureHeadline:
type: headline
label: Positive setting culture
primaryPositiveSettingCultureLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
primaryPositiveSettingCulturePoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
primaryPositiveSettingCultureTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
secondary:
when:
settingType: secondary
type: fields
fields:
secondaryProjectDeliveryTeamHeadline:
type: headline
label: Project delivery team
secondaryProjectDeliveryTeamLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
secondaryProjectDeliveryTeamPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
secondaryProjectDeliveryTeamTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
secondaryInvolvingSettingStaffHeadline:
type: headline
label: Involving setting staff
secondaryInvolvingSettingStaffLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
secondaryInvolvingSettingStaffPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
secondaryInvolvingSettingStaffTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
secondaryWorkingWithChildrenHeadline:
type: headline
label: Working with children & young people
secondaryWorkingWithChildrenLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
secondaryWorkingWithChildrenPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
secondaryWorkingWithChildrenTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
secondaryInvolvingFamiliesAndCommunitiesHeadline:
type: headline
label: Involving families & communities
secondaryInvolvingFamiliesAndCommunitiesLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
secondaryInvolvingFamiliesAndCommunitiesPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
secondaryInvolvingFamiliesAndCommunitiesTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
secondaryPositiveSettingCultureHeadline:
type: headline
label: Positive setting culture
secondaryPositiveSettingCultureLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
secondaryPositiveSettingCulturePoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
secondaryPositiveSettingCultureTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
alternative:
when:
settingType: alternative
type: fields
fields:
alternativeProjectDeliveryTeamHeadline:
type: headline
label: Project delivery team
alternativeProjectDeliveryTeamLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
alternativeProjectDeliveryTeamPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
alternativeProjectDeliveryTeamTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
alternativeInvolvingSettingStaffHeadline:
type: headline
label: Involving setting staff
alternativeInvolvingSettingStaffLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
alternativeInvolvingSettingStaffPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
alternativeInvolvingSettingStaffTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
alternativeWorkingWithChildrenHeadline:
type: headline
label: Working with children & young people
alternativeWorkingWithChildrenLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
alternativeWorkingWithChildrenPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
alternativeWorkingWithChildrenTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
alternativeInvolvingFamiliesAndCommunitiesHeadline:
type: headline
label: Involving families & communities
alternativeInvolvingFamiliesAndCommunitiesLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
alternativeInvolvingFamiliesAndCommunitiesPoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
alternativeInvolvingFamiliesAndCommunitiesTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
alternativePositiveSettingCultureHeadline:
type: headline
label: Positive setting culture
alternativePositiveSettingCultureLeadershipAndCommunicationKeyTasks:
extends: fields/setting-tasks
label: Leadership & communication key tasks
alternativePositiveSettingCulturePoliciesAndCurriculumKeyTasks:
extends: fields/setting-tasks
label: Policies & curriculum key tasks
alternativePositiveSettingCultureTimetableAndPlanningKeyTasks:
extends: fields/setting-tasks
label: Timetable & planning key tasks
university:
when:
settingType: university
type: fields
fields:
universitiesProjectDeliveryTeamHeadline:
type: headline
label: Project delivery team
universitiesProjectDeliveryTeamKeyTasks:
extends: fields/setting-tasks
label: Key tasks
universitiesInvolvingStaffHeadline:
type: headline
label: Involving staff
universitiesInvolvingStaffKeyTasks:
extends: fields/setting-tasks
label: Key tasks
universitiesWorkingWithStudentsAndStudentLeadersHeadline:
type: headline
label: Working with students and student leaders
universitiesWorkingWithStudentsAndStudentLeadersKeyTasks:
extends: fields/setting-tasks
label: Key tasks
universitiesInvolvingTheWiderCommunityHeadline:
type: headline
label: Involving the wider community
universitiesInvolvingTheWiderCommunityKeyTasks:
extends: fields/setting-tasks
label: Key tasks
universitiesDevelopingAPositiveCampusCultureHeadline:
type: headline
label: Developing a positive campus culture
universitiesDevelopingAPositiveCampusCultureKeyTasks:
extends: fields/setting-tasks
label: Key tasks
postDeliveryTab:
label: Post delivery questionnaires
icon: question
I don’t have a specific section set up in the blueprint for pages - is this the issue?
Super, thank you.
Before I get stuck into this, is $page->copy() available to me in 4.8? It isn’t documented but it seems to be in the page actions. It would make what I am trying to do a lot easier, otherwise I think I will need to duplicate and then move the page.
Yes, only hidden from the docs because it was marked as @internal in the doc block.
1 Like