{# "Edit Element" layout template The following variables should be defined by the sub-template: - element: the source element or one of its drafts/revisions - canDeleteDraft (optional): whether the current user is allowed to delete the draft (if it is one). If the current user created the draft, then it will be deletable regardless. - canUpdateSource (optional): whether the current user is allowed to update the source element (e.g. by publishing a draft or reverting the element to a prior revision). - shareUrl (optional): the URL that the Share button should link to. - saveDraftAction: the controller action that should be used to save a draft - deleteDraftAction: the controller action that should be used to delete a draft - applyDraftAction: the controller action that should be used to apply a draft onto the source element - revertSourceAction: the controller action that should be used to revert the source element to a revision - showStatusToggles: whether the “Enabled” / “Enabled” for ” fields should be added to the details pane #} {% extends '_layouts/cp' %} {% import '_includes/forms' as forms %} {% set source = element.draftId or element.revisionId ? element.getSource() : element %} {% set isMultiSiteElement = craft.app.isMultiSite and element.supportedSites|length > 1 %} {% set previewTargets = CraftEdition == CraftPro ? (element.previewTargets ?? []) : [] %} {% if source.uri %} {% set previewTargets = [{ label: 'Primary {type} page'|t('app', { type: element.displayName()|lower }), url: element.uri }]|merge(previewTargets) %} {% endif %} {% set enablePreview = previewTargets and not craft.app.request.isMobileBrowser(true) %} {% set canDeleteDraft = element.draftId and ((canDeleteDraft ?? false) or element.creatorId == currentUser.id) %} {% set canUpdateSource = canUpdateSource ?? false %} {% set shareUrl = shareUrl ?? null %} {% set revertSourceAction = revertSourceAction ?? null %} {% if canUpdateSource and not element.revisionId %} {% set fullPageForm = true %} {% endif %} {% if element.draftId %} {% do craft.app.session.authorize('previewDraft:' ~ element.draftId) %} {% elseif not element.revisionId %} {% do craft.app.session.authorize('previewElement:' ~ element.id) %} {% endif %} {% set showStatusToggles = element.hasStatuses() and (showStatusToggles ?? true) %} {% block header %} {{ block('pageTitle') }} {{ block('contextMenu') }}
{% if not element.revisionId and previewTargets %}
{% if enablePreview %}
{{ "Preview"|t('app') }}
{% endif %}
{{ 'Share'|t('app') }}
{% endif %} {{ block('actionButton') }} {% endblock %} {% block contextMenu %} {% include "_includes/revisionmenu" %} {% endblock %} {% block actionButton %} {% if canUpdateSource %} {% if element.revisionId and revertSourceAction %}
{{ csrfInput() }} {{ redirectInput(element.cpEditUrl) }}
{% else %}
{% endif %} {% endif %} {% endblock %} {% block main %} {% if canUpdateSource and craft.app.isMultiSite %} {% endif %} {{ parent() }} {% endblock %} {% block details %}
{% block settings %} {% if showStatusToggles %} {{ forms.lightswitchField({ label: isMultiSiteElement ? 'Enabled Globally'|t('app') : 'Enabled'|t('app'), id: 'enabled', name: 'enabled', on: element.enabled, disabled: element.revisionId, toggle: 'enabledForSite-field' }) }} {% if isMultiSiteElement %} {{ forms.lightswitchField({ fieldClass: not element.enabled ? 'hidden', label: "Enabled for {site}"|t('app', { site: element.site.name|t('site') }), id: 'enabledForSite', name: 'enabledForSite', on: element.enabledForSite, disabled: element.revisionId }) }} {% endif %} {% endif %} {% endblock %}
{% block meta %}
{{ "Created at"|t('app') }}
{{ element.dateCreated|datetime('short') }}
{{ "Updated at"|t('app') }}
{{ element.dateUpdated|datetime('short') }}
{% if element.revisionId %} {% set revisionNotes = element.revisionNotes %} {% elseif not element.draftId and element.currentRevision %} {% set revisionNotes = element.currentRevision.revisionNotes %} {% else %} {% set revisionNotes = null %} {% endif %} {% if revisionNotes %}
{{ "Notes"|t('app') }}
{{ revisionNotes }}
{% endif %} {% endblock %}
{% endblock %} {% if not element.revisionId %} {% set normalizedPreviewTargets = [] %} {% set scheme = craft.app.request.isSecureConnection ? 'https': null %} {% for target in previewTargets %} {% set path = target.url ?? view.renderObjectTemplate(target.urlFormat, element) %} {% set normalizedPreviewTargets = normalizedPreviewTargets|merge([{ label: target.label|t('site'), url: siteUrl(path, scheme=scheme, siteId=element.siteId) }]) %} {% endfor %} {% set settings = { elementType: className(element), sourceId: element.sourceId, siteId: element.siteId, isLive: not element.draftId and not element.revisionId and element.enabled and element.enabledForSite, sourceEditUrl: element.cpEditUrl, draftId: element.draftId, draftName: element.draftId ? element.draftName : null, draftNotes: element.draftId ? element.draftNotes : null, canDeleteDraft: canDeleteDraft, canUpdateSource: canUpdateSource, saveDraftAction: saveDraftAction, deleteDraftAction: deleteDraftAction, applyDraftAction: applyDraftAction, enablePreview: enablePreview, previewTargets: normalizedPreviewTargets, } %} {% js %} new Craft.DraftEditor({{ settings|json_encode|raw }}); {% endjs %} {% endif %}