Ejemplo n.º 1
0
/**
 * Form submit handler for the theme settings form.
 */
function at_core_submit_layouts(&$form, &$form_state) {
  $build_info = $form_state->getBuildInfo();
  $values = $form_state->getValues();
  $theme = $build_info['args'][0];

  // Generate and save a new layout.
  if (isset($values['settings_layouts_enable']) && $values['settings_layouts_enable'] == 1) {

    $generateLayout = new LayoutSubmit($theme, $values);

    // Update the themes info file with new regions.
    $generateLayout->saveLayoutRegions();

    // Build and save the suggestions layout css files.
    $generateLayout->saveLayoutSuggestionsCSS();

    // Build and save the suggestions twig templates.
    $generateLayout->saveLayoutSuggestionsMarkup();

    // Add a new suggestion to the page suggestions array in config.
    if (!empty($values['ts_name'])) {
      $suggestion = trim($values['ts_name']);
      $clean_suggestion = str_replace('-', '_', $suggestion);
      $values["settings_suggestion_page__$clean_suggestion"] = $clean_suggestion;
    }

    // Delete suggestion files
    $templates_directory = drupal_get_path('theme', $theme) . '/templates/page';
    $css_directory = $values['settings_generated_files_path'];

    foreach ($values as $values_key => $values_value) {
      if (substr($values_key, 0, 18) === 'delete_suggestion_') {
        if ($values_value === 1) {
          $delete_suggestion_keys[] = Unicode::substr($values_key, 18);
        }
      }
    }

    if (isset($delete_suggestion_keys)) {
      foreach ($delete_suggestion_keys as $suggestion_to_remove) {
        $formatted_suggestion = str_replace('_', '-', $suggestion_to_remove);
        $template_file_path = $templates_directory . '/' . $formatted_suggestion . '.html.twig';
        $css_file_path = $css_directory . '/' . $theme . '--layout__' . $formatted_suggestion . '.css';
        if (file_exists($template_file_path)) {unlink($template_file_path);}
        if (file_exists($css_file_path)) {unlink($css_file_path);}
      }
    }
  }

  // Flush all caches. This is the only realy reliable way I have found to ensure
  // new templates and layouts work correctly.
  drupal_flush_all_caches();

  // Manage settings and configuration.
  // Must get mutable config otherwise bad things happen.
  $config = \Drupal::configFactory()->getEditable($theme . '.settings');
  $convertToConfig = new ThemeSettingsConfig();
  $convertToConfig->settingsConvertToConfig($values, $config);
}
/**
 * Form submit handler for the Extension settings.
 * @param $form
 * @param $form_state
 */
function at_core_submit_extension_settings(&$form, &$form_state)
{
    $build_info = $form_state->getBuildInfo();
    $values = $form_state->getValues();
    $theme = $build_info['args'][0];
    $at_core_path = drupal_get_path('theme', 'at_core');
    // Don't let this timeout easily.
    set_time_limit(60);
    // Path to save generated CSS files.
    $generated_files_path = $values['settings_generated_files_path'];
    if ($values['settings_enable_extensions'] === 1) {
        // Require submit handlers and helper functions for extensions.
        if (isset($values['settings_enable_fonts']) && $values['settings_enable_fonts'] === 1 || isset($values['settings_enable_titles']) && $values['settings_enable_titles'] === 1) {
            require_once $at_core_path . '/forms/ext/fonts.inc';
            require_once $at_core_path . '/forms/ext/fonts_submit.php';
            require_once $at_core_path . '/forms/ext/titles_submit.php';
        }
        // Submit handler for Fonts.
        if (isset($values['settings_enable_fonts']) && $values['settings_enable_fonts'] === 1) {
            // Returns modified values to pass in new settings for typekit and google fonts.
            $values = at_core_submit_fonts($values, $generated_files_path);
        }
        // Submit handler for Titles.
        if (isset($values['settings_enable_titles']) && $values['settings_enable_titles'] === 1) {
            at_core_submit_titles($values, $generated_files_path);
        }
        // Submit handler for Markup Overrides.
        if (isset($values['settings_enable_markup_overrides']) && $values['settings_enable_markup_overrides'] === 1) {
            // Breadcrumbs
            if (!empty($values['settings_breadcrumb_separator'])) {
                require_once $at_core_path . '/forms/ext/breadcrumb_submit.php';
                at_core_submit_breadcrumb($values, $generated_files_path);
            }
        }
        // Submit handler for Mobile blocks.
        if (isset($values['settings_enable_mobile_blocks']) && $values['settings_enable_mobile_blocks'] === 1) {
            require_once $at_core_path . '/forms/ext/mobile_blocks_submit.php';
            at_core_submit_mobile_blocks($values, $theme, $generated_files_path);
        }
        // Submit handler for Custom CSS.
        if (isset($values['settings_enable_custom_css']) && $values['settings_enable_custom_css'] === 1) {
            require_once $at_core_path . '/forms/ext/custom_css_submit.php';
            at_core_submit_custom_css($values, $generated_files_path);
        }
    }
    // Flush caches. I really, really tried to avoid this, but if you know a better
    // way of always clearing twig, CSS and the registry?
    drupal_flush_all_caches();
    // Manage settings and configuration.
    // Must get mutable config otherwise bad things happen.
    $config = \Drupal::configFactory()->getEditable($theme . '.settings');
    $convertToConfig = new ThemeSettingsConfig();
    $convertToConfig->settingsExtensionsConvertToConfig($values, $config);
    drupal_set_message(t('Extensions configuration saved.'), 'status');
    //$performance_url = Url::fromRoute('system.performance_settings')->setOptions(array('attributes' => array('target' => '_blank')));
    //drupal_set_message(t('Extensions configuration saved. If settings have not taken effect, please <b>@perm</b>.', array('@perm' => \Drupal::l(t('clear the cache'), $performance_url))), 'status');
}
Ejemplo n.º 3
0
/**
 * Form submit handler for the theme settings form.
 */
function at_core_submit_extension_settings(&$form, &$form_state) {
  $build_info = $form_state->getBuildInfo();
  $values = $form_state->getValues();
  $theme = $build_info['args'][0];
  $at_core_path = drupal_get_path('theme', 'at_core');

  // Path to save generated CSS files.
  $generated_files_path = $values['settings_generated_files_path'];

  if ($values['settings_enable_extensions'] === 1) {

    // Require submit handlers and helper functions for extensions. TODO - convert to classes and methods?
    if ((isset($values['settings_enable_fonts']) && $values['settings_enable_fonts'] === 1) ||
        (isset($values['settings_enable_titles']) && $values['settings_enable_titles'] === 1)) {
      require_once($at_core_path . '/forms/ext/fonts.inc');
      require_once($at_core_path . '/forms/ext/fonts_submit.php');
      require_once($at_core_path . '/forms/ext/titles_submit.php');
    }

    // Submit handler for Fonts.
    if (isset($values['settings_enable_fonts']) && $values['settings_enable_fonts'] === 1) {
      at_core_submit_fonts($values, $theme, $generated_files_path);
    }

    // Submit handler for Titles.
    if (isset($values['settings_enable_titles']) && $values['settings_enable_titles'] === 1) {
      at_core_submit_titles($values, $theme, $generated_files_path);
    }

    // Submit handler for Markup Overrides.
    if (isset($values['settings_enable_markup_overrides']) && $values['settings_enable_markup_overrides'] === 1) {

      // Breadcrumbs
      if (!empty($values['settings_breadcrumb_separator'])) {
        require_once($at_core_path . '/forms/ext/breadcrumb_submit.php');
        at_core_submit_breadcrumb($values, $theme, $generated_files_path);
      }

      // Login block.
      if (isset($values['settings_horizontal_login_block']) && $values['settings_horizontal_login_block'] === 1) {
        require_once($at_core_path . '/forms/ext/login_block_submit.php');
        at_core_submit_login_block($values, $theme, $generated_files_path);
      }
    }

    // Submit handler for Mobile blocks.
    if (isset($values['settings_enable_mobile_blocks']) && $values['settings_enable_mobile_blocks'] === 1) {
      require_once($at_core_path . '/forms/ext/mobile_blocks_submit.php');
      at_core_submit_mobile_blocks($values, $theme, $generated_files_path);
    }

    // Submit handler for Custom CSS.
    if (isset($values['settings_enable_custom_css']) && $values['settings_enable_custom_css'] === 1) {
      require_once($at_core_path . '/forms/ext/custom_css_submit.php');
      at_core_submit_custom_css($values, $theme, $generated_files_path);
    }
  }

  // Flush all caches, this is the only 100% reliable way to make sure all settings are applied.
  drupal_flush_all_caches();

  // Manage settings and configuration.
  // Must get mutable config otherwise bad things happen.
  $config = \Drupal::configFactory()->getEditable($theme . '.settings');
  $convertToConfig = new ThemeSettingsConfig();
  $convertToConfig->settingsConvertToConfig($values, $config);

  drupal_set_message(t('Extensions configuration saved. Cache cleared.'), 'status');
}
Ejemplo n.º 4
0
/**
 * Form submit handler for the Layout settings.
 * @param $form
 * @param $form_state
 */
function at_core_submit_layouts(&$form, &$form_state)
{
    $build_info = $form_state->getBuildInfo();
    $values = $form_state->getValues();
    $theme = $build_info['args'][0];
    // Don't let this timeout easily.
    set_time_limit(60);
    // Generate and save a new layout.
    if (isset($values['settings_layouts_enable']) && $values['settings_layouts_enable'] == 1) {
        $generateLayout = new LayoutSubmit($theme, $values);
        // Update the themes info file with new regions.
        $generateLayout->saveLayoutRegions();
        // Build and save the suggestions layout css files.
        $generateLayout->saveLayoutSuggestionsCSS();
        // Build and save the suggestions twig templates.
        $generateLayout->saveLayoutSuggestionsMarkup();
        // Add a new suggestion to the page suggestions array in config.
        if (!empty($values['ts_name'])) {
            $suggestion = trim($values['ts_name']);
            $clean_suggestion = str_replace('-', '_', $suggestion);
            $values["settings_suggestion_page__{$clean_suggestion}"] = $clean_suggestion;
        }
        // Delete suggestion files
        $templates_directory = drupal_get_path('theme', $theme) . '/templates/generated';
        $css_directory = $values['settings_generated_files_path'];
        foreach ($values as $values_key => $values_value) {
            if (substr($values_key, 0, 18) === 'delete_suggestion_') {
                if ($values_value === 1) {
                    $delete_suggestion_keys[] = Unicode::substr($values_key, 18);
                }
            }
        }
        if (isset($delete_suggestion_keys)) {
            foreach ($delete_suggestion_keys as $suggestion_to_remove) {
                $formatted_suggestion = str_replace('_', '-', $suggestion_to_remove);
                $template_file_name = $formatted_suggestion . '.html.twig';
                $css_file_name = $theme . '.layout.' . $formatted_suggestion . '.css';
                $template_file_path = "{$templates_directory}/{$template_file_name}";
                $css_file_path = "{$css_directory}/{$css_file_name}";
                $files_to_delete[] = $template_file_name;
                $files_to_delete[] = $css_file_name;
                if (file_exists($template_file_path)) {
                    unlink($template_file_path);
                }
                if (file_exists($css_file_path)) {
                    unlink($css_file_path);
                }
            }
        }
    }
    if (isset($files_to_delete)) {
        $deleted_files_message_list = array('#theme' => 'item_list', '#items' => $files_to_delete);
        drupal_set_message(t('The following <b>files</b> were removed: @removed_files', array('@removed_files' => \Drupal::service('renderer')->renderPlain($deleted_files_message_list))), 'status');
    }
    // Flush caches. I really, really tried to avoid this, but if you know a better
    // way of always clearing twig, CSS and the registry?
    drupal_flush_all_caches();
    // Manage settings and configuration.
    $config = \Drupal::configFactory()->getEditable($theme . '.settings');
    $convertToConfig = new ThemeSettingsConfig();
    $convertToConfig->settingsLayoutConvertToConfig($values, $config);
    //$performance_url = Url::fromRoute('system.performance_settings')->setOptions(array('attributes' => array('target' => '_blank')));
    //drupal_set_message(t('Layout settings saved. If settings have not taken effect, please <b>@perm</b>.', array('@perm' => \Drupal::l(t('clear the cache'), $performance_url))), 'status');
}