diff --git a/gin.theme b/gin.theme index 6541512..c8cab7a 100755 --- a/gin.theme +++ b/gin.theme @@ -108,6 +108,9 @@ function gin_theme_suggestions_page_alter(&$suggestions, $variables) { $arg = str_replace(["/", '-'], ['_', '_'], $path); $suggestions[] = 'page__' . $arg; } + if (_gin_is_content_form()) { + $suggestions[] = 'page__content_form'; + } } /** @@ -200,8 +203,28 @@ function gin_preprocess_dropbutton_wrapper(&$variables) { function gin_form_alter(&$form, $form_state, $form_id) { // Are we on an edit form? if (_gin_is_content_form($form, $form_state, $form_id)) { + + // Attach library. + $form['#attached']['library'][] = 'gin/gin_editform'; + + $form['#theme'][] = 'node_edit_form'; + $form['#theme'][] = 'node_form'; + $form['#attributes']['class'][] = 'node-form'; + $form['#attached']['library'][] = 'node/form'; + $form['#attached']['library'][] = 'claro/node-form'; + + $form['advanced']['#type'] = 'container'; + $form['advanced']['#accordion'] = TRUE; + + $form['meta']['#type'] = 'container'; + $form['meta']['#access'] = TRUE; + // Action buttons. if (isset($form['actions'])) { + // Submit change weight. + if (isset($form['actions']['submit'])) { + $form['actions']['submit']['#weight'] = '99'; + } // Create gin_actions group. $form['gin_actions'] = [ '#type' => 'container', @@ -246,9 +269,6 @@ function gin_form_alter(&$form, $form_state, $form_id) { unset($form['gin_sidebar']['actions']['preview']); unset($form['gin_sidebar']['actions']['submit']); } - - // Attach library. - $form['#attached']['library'][] = 'gin/gin_editform'; } // If not logged in hide changed and author node info on add forms. @@ -1234,14 +1254,64 @@ function _gin_is_content_form($form = NULL, $form_state = NULL, $form_id = NULL) // Routes to include. $route_names = [ + '/^node\.add$/', + '/^quick_node_clone\.(.(?!_type))*\.quick_clone$/', + '/^entity\.(.(?!_type))*\.add_form$/', + '/^entity\.(.(?!_type))*\.content_translation_add$/', + '/^entity\.(.(?!_type))*\.edit_form$/', + ]; + $included_entity_types = [ + 'node', + 'taxonomy_term', + ]; + $excluded_entity_types = [ + 'block_content', + 'entity_browser', + 'entity_form_mode', + 'entity_view_mode', + 'crop', + 'file', + 'date_format', + 'filter_format', + 'image_style', + 'media', + 'menu', + 'menu_link_content', + 'metatag_defaults', + 'path_alias', + 'pathauto_pattern', + 'paragraph', + 'responsive_image_style', + 'search_api_index', + 'search_api_server', + 'search_api_task', + 'shortcut', + 'shortcut_set', + 'taxonomy_vocabulary', + 'view', + 'webform', + 'webform_options', + ]; + $included_routes = [ 'node.add', - 'entity.node.content_translation_add', - 'quick_node_clone.node.quick_clone', - 'entity.node.edit_form', ]; + foreach ($included_entity_types as $included_entity_type) { + $included_routes[] = 'quick_node_clone.' . $included_entity_type . '.quick_clone'; + $included_routes[] = 'entity.' . $included_entity_type . '.add_form'; + $included_routes[] = 'entity.' . $included_entity_type . '.content_translation_add'; + $included_routes[] = 'entity.' . $included_entity_type . '.edit_form'; + } + $excluded_routes = []; + foreach ($excluded_entity_types as $excluded_entity_type) { + $excluded_routes[] = 'quick_node_clone.' . $excluded_entity_type . '.quick_clone'; + $excluded_routes[] = 'entity.' . $excluded_entity_type . '.add_form'; + $excluded_routes[] = 'entity.' . $excluded_entity_type . '.content_translation_add'; + $excluded_routes[] = 'entity.' . $excluded_entity_type . '.edit_form'; + } if ( - in_array($route_name, $route_names, TRUE) || + in_array($route_name, $included_routes) && !in_array($route_name, $excluded_routes) || + // array_reduce($route_names, function($is_matching, $route_pattern) use ($route_name, $excluded_routes) { return $is_matching || preg_match($route_pattern, $route_name); }, false) || ($form_state && ($form_state->getBuildInfo()['base_form_id'] ?? NULL) === 'node_form') || ($route_name === 'entity.group_content.create_form' && strpos($form_id, 'group_node') === FALSE) ) { diff --git a/templates/page/page--clone.html.twig b/templates/page/page--clone.html.twig index 79b531c..e44829e 100644 --- a/templates/page/page--clone.html.twig +++ b/templates/page/page--clone.html.twig @@ -1 +1 @@ -{% extends '@gin/page/page--node.html.twig' %} +{% extends '@gin/page/page--content-form.html.twig' %} diff --git a/templates/page/page--group.html.twig b/templates/page/page--group.html.twig index 79b531c..e44829e 100644 --- a/templates/page/page--group.html.twig +++ b/templates/page/page--group.html.twig @@ -1 +1 @@ -{% extends '@gin/page/page--node.html.twig' %} +{% extends '@gin/page/page--content-form.html.twig' %} diff --git a/templates/page/page--node-add.html.twig b/templates/page/page--node-add.html.twig index 426580a..e44829e 100644 --- a/templates/page/page--node-add.html.twig +++ b/templates/page/page--node-add.html.twig @@ -1 +1 @@ -{% extends '@gin/page/page.html.twig' %} +{% extends '@gin/page/page--content-form.html.twig' %} diff --git a/templates/page/page--node.html.twig b/templates/page/page--node.html.twig index b58c268..e44829e 100644 --- a/templates/page/page--node.html.twig +++ b/templates/page/page--node.html.twig @@ -1,45 +1 @@ -{# -/** - * @file - * Claro's theme implementation to display a single Drupal page. - * - * The doctype, html, head, and body tags are not in this template. Instead - * they can be found in the html.html.twig template normally located in the - * core/modules/system directory. - * - * Available variables: - * - * General utility variables: - * - base_path: The base URL path of the Drupal installation. Will usually be - * "/" unless you have installed Drupal in a sub-directory. - * - is_front: A flag indicating if the current page is the front page. - * - logged_in: A flag indicating if the user is registered and signed in. - * - is_admin: A flag indicating if the user has permission to access - * administration pages. - * - * Site identity: - * - front_page: The URL of the front page. Use this instead of base_path when - * linking to the front page. This includes the language domain or prefix. - * - * Page content (in order of occurrence in the default page.html.twig): - * - node: Fully loaded node, if there is an automatically-loaded node - * associated with the page and the node ID is the second argument in the - * page's path (e.g. node/12345 and node/12345/revisions, but not - * comment/reply/12345). - * - * Regions: - * - page.header: Items for the header region. - * - page.pre_content: Items for the pre-content region. - * - page.breadcrumb: Items for the breadcrumb region. - * - page.highlighted: Items for the highlighted region. - * - page.help: Dynamic help text, mostly for admin pages. - * - page.content: The main content of the current page. - * - * @see template_preprocess_page() - * @see html.html.twig - */ -#} - -
- {% include '@gin/page/page.html.twig' %} -
+{% extends '@gin/page/page--content-form.html.twig' %}