1 standard.install standard_install()

Implements hook_install().

Perform actions to set up the site for this profile.

See also

system_install()

File

core/profiles/standard/standard.install, line 14
Install/uninstall and update functions for the standard installation profile.

Code

function standard_install() {
  // Add text formats.
  // Changed the display name from "Filtered HTML" to "Basic", but kept the
  // machine name as "filtered_html" for backward compatibility.
  $filtered_html_format = array(
    'format' => 'filtered_html',
    'name' => 'Basic',
    'weight' => 0,
    'editor' => 'ckeditor5',
    'editor_settings' => array(
      'image_upload' => array(
        'status' => 1,
        'dimensions' => array('max_width' => '', 'max_height' => ''),
        'max_size' => NULL,
        'scheme' => 'public',
        'directory' => 'inline-images',
      ),
    ),
    'filters' => array(
      'filter_url' => array(
        'weight' => 0,
        'status' => 1,
      ),
      'filter_html' => array(
        'weight' => 1,
        'status' => 1,
      ),
      // Line break filter.
      'filter_autop' => array(
        'weight' => 2,
        'status' => 1,
      ),
      'filter_image_caption' => array(
        'weight' => 4,
        'status' => 1,
      ),
      'filter_image_align' => array(
        'weight' => 4,
        'status' => 1,
      ),
      'filter_htmlcorrector' => array(
        'weight' => 10,
        'status' => 1,
      ),
    ),
  );
  $filtered_html_format = (object) $filtered_html_format;
  filter_format_save($filtered_html_format);

  // Changed the display name from "Full HTML" to "Raw HTML", but kept the
  // machine name as "full_html" for backward compatibility.
  $full_html_format = array(
    'format' => 'full_html',
    'name' => 'Raw HTML',
    'weight' => 1,
    'editor' => NULL,
    'filters' => array(
      'filter_url' => array(
        'weight' => 0,
        'status' => 1,
      ),
      // Line break filter.
      'filter_autop' => array(
        'weight' => 1,
        'status' => 1,
      ),
      'filter_image_caption' => array(
        'weight' => 4,
        'status' => 1,
      ),
      'filter_image_align' => array(
        'weight' => 4,
        'status' => 1,
      ),
      'filter_htmlcorrector' => array(
        'weight' => 10,
        'status' => 1,
      ),
    ),
  );
  $full_html_format = (object) $full_html_format;
  filter_format_save($full_html_format);

  // Enable Basis theme and set it as default theme instead of Stark.
  // @see system_install()
  $default_theme = 'basis';
  config_set('system.core', 'theme_default', $default_theme);
  theme_enable(array($default_theme));
  theme_disable(array('stark'));

  // Set home page to "home".
  config_set('system.core', 'site_frontpage', 'home');
  backdrop_flush_all_caches();

  // Create default pre-defined node types. For a complete list of available
  // node type attributes please refer to the node type API documentation at:
  // https://docs.backdropcms.org/api/backdrop/core!modules!node!node.module/function/node_type_save
  $types = array(
    array(
      'type' => 'page',
      'name' => st('Page'),
      'description' => st("Add a page with static content, like the 'About' page."),
      'settings' => array(
        'status_default' => NODE_PUBLISHED,
        'promote_enabled' => FALSE,
        'node_preview' => TRUE,
        'promote_default' => FALSE,
        'sticky_enabled' => FALSE,
        'sticky_default' => FALSE,
        'revision_enabled' => TRUE,
        'revision_default' => FALSE,
        'node_submitted' => FALSE,
        'node_user_picture' => FALSE,
        'comment_default' => COMMENT_NODE_CLOSED,
        'menu_default' => TRUE,
        'menu_options' => array('main-menu'),
      ),
      'is_new' => TRUE,
    ),
    array(
      'type' => 'post',
      'name' => st('Post'),
      'description' => st('Add a blog post, news article, or press release.'),
      'settings' => array(
        'status_default' => NODE_PUBLISHED,
        'node_preview' => TRUE,
        'promote_enabled' => TRUE,
        'promote_default' => TRUE,
        'sticky_enabled' => TRUE,
        'sticky_default' => FALSE,
        'revision_enabled' => TRUE,
        'revision_default' => FALSE,
        'show_submitted_info' => TRUE,
        'comment_default' => COMMENT_NODE_OPEN,
        'node_submitted' => TRUE,
        'node_user_picture' => TRUE,
      ),
      'is_new' => TRUE,
    ),
    array(
      'type' => 'card',
      'name' => st('Card'),
      'description' => st('Add a card for use on an existing page. Display as a block or in a view.'),
      'settings' => array(
        'status_default' => NODE_PUBLISHED,
        'node_preview' => TRUE,
        'promote_enabled' => TRUE,
        'promote_default' => FALSE,
        'sticky_enabled' => FALSE,
        'sticky_default' => FALSE,
        'revision_enabled' => TRUE,
        'revision_default' => FALSE,
        'scheduling_enabled' => FALSE,
        'show_submitted_info' => FALSE,
        'comment_default' => COMMENT_NODE_CLOSED,
        'node_submitted' => FALSE,
        'node_user_picture' => FALSE,
        'hidden_path' => TRUE,
      ),
      'is_new' => TRUE,
    ),
  );

  foreach ($types as $type) {
    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
  }

  // Add default alias for page content types.
  config('path.settings')
    ->set('node_page_pattern', '[node:title]')
    ->set('node_post_pattern', 'posts/[node:title]')
    ->set('node_card_pattern', 'node/[node:nid]')
    ->save();

  cache_clear_all();

  // Create a default vocabulary named "Tags", enabled for the "post" content
  // type.
  $description = st('Use tags to group posts on similar topics into categories.');
  $vocabulary = new TaxonomyVocabulary(array(
    'name' => st('Tags'),
    'description' => $description,
    'machine_name' => 'tags',
  ));
  taxonomy_vocabulary_save($vocabulary);

  $field = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'type' => 'taxonomy_term_reference',
    // Set cardinality to unlimited for tagging.
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  $help = st('Enter a comma-separated list of words to describe your content.');
  $instance = array(
    'field_name' => 'field_' . $vocabulary->machine_name,
    'entity_type' => 'node',
    'label' => 'Tags',
    'bundle' => 'post',
    'description' => $help,
    'widget' => array(
      'type' => 'taxonomy_autocomplete',
      'weight' => -4,
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
        'weight' => 10,
      ),
      'teaser' => array(
        'type' => 'taxonomy_term_reference_link',
        'weight' => 10,
      ),
    ),
  );
  field_create_instance($instance);


  // Create an image field named "Image", enabled for the "post" content type.
  // Many of the following values will be defaulted. They're included here as
  // an illustrative example.
  // See https://docs.backdropcms.org/api/backdrop/core%21modules%21field%21field.crud.inc/function/field_create_field/1

  $field = array(
    'field_name' => 'field_image',
    'type' => 'image',
    'cardinality' => 1,
    'locked' => FALSE,
    'indexes' => array('fid' => array('fid')),
    'settings' => array(
      'uri_scheme' => 'public',
      'default_image' => FALSE,
    ),
    'storage' => array(
      'type' => 'field_sql_storage',
      'settings' => array(),
    ),
  );
  field_create_field($field);


  // Many of the following values will be defaulted, they're included here as
  // an illustrative example.
  // See https://docs.backdropcms.org/api/backdrop/core%21modules%21field%21field.crud.inc/function/field_create_instance/1
  $instance = array(
    'field_name' => 'field_image',
    'entity_type' => 'node',
    'label' => 'Image',
    'bundle' => 'post',
    'description' => st('Upload an image to go with this post.'),
    'required' => FALSE,

    'settings' => array(
      'file_directory' => 'field/image',
      'file_extensions' => implode(' ', image_get_supported_extensions()),
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'alt_field' => TRUE,
      'title_field' => '',
    ),

    'widget' => array(
      'type' => 'image_image',
      'settings' => array(
        'progress_indicator' => 'throbber',
        'preview_image_style' => 'thumbnail',
      ),
      'weight' => -1,
    ),

    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array('image_style' => 'large', 'image_link' => ''),
        'weight' => -1,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array(
          'image_style' => 'medium',
          'image_link' => 'content',
          'image_float' => 'right',
        ),
        'weight' => -1,
      ),
    ),
  );
  field_create_instance($instance);

  $instance = array(
    'field_name' => 'field_image',
    'entity_type' => 'node',
    'label' => 'Image',
    'bundle' => 'card',
    'description' => st('Upload an image to go with this card.'),
    'required' => FALSE,

    'settings' => array(
      'file_directory' => 'field/image',
      'file_extensions' => implode(' ', image_get_supported_extensions()),
      'max_filesize' => '',
      'max_resolution' => '',
      'min_resolution' => '',
      'alt_field' => TRUE,
      'title_field' => '',
    ),

    'widget' => array(
      'type' => 'image_image',
      'settings' => array(
        'progress_indicator' => 'throbber',
        'preview_image_style' => 'thumbnail',
      ),
      'weight' => -1,
    ),

    'display' => array(
      'default' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array('image_style' => 'large', 'image_link' => ''),
        'weight' => 0,
      ),
      'teaser' => array(
        'label' => 'hidden',
        'type' => 'image',
        'settings' => array(
          'image_style' => 'medium',
          'image_link' => '',
          'image_float' => '',
        ),
        'weight' => -1,
      ),
    ),
  );
  field_create_instance($instance);

  // Create a default post to display on front page.
  $post = new Node(
  array(
    'title' => st('Your first post!'),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => '<p>' . st('This is your first post! You may edit or delete it.') . '</p>',
          'format' => 'filtered_html',
        ),
      ),
    ),
    'uid' => 1,
    'status' => 1,
    'promote' => 1,
    'type' => 'post',
  )
  );
  $post->save();

  // Create an "About" page node.
  $page = new Node(
  array(
    'title' => st('About'),
    'body' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => '<p>' . st('This is a page with static content. You may edit or delete it.') . '</p>',
          'format' => 'filtered_html',
        ),
      ),
    ),
    'uid' => 1,
    'status' => 1,
    'promote' => 0,
    'type' => 'page',
  )
  );
  $page->save();

  // Create an "About" link in the main menu.
  $item = array(
    'link_path' => 'node/' . $page->nid,
    'link_title' => 'About',
    'weight' => 1,
  );
  menu_link_save($item);

  // Creating three default Card nodes.
  // Special thanks to @indigoxela for providing the icons.
  $field_image_dir = 'public://field/image';
  file_prepare_directory($field_image_dir, FILE_CREATE_DIRECTORY);

  $cards = array(
    'card1-layout.png' => array(
      'title' => st('The Home page layout'),
      'body' => st('<p>Use the home page layout to specifically customize this page. These Cards only appear on this layout.</p><p><a href="https://docs.backdropcms.org/documentation/the-home-page">Learn more about the Home page</a></p>'),
    ),
    'card2-card.png' => array(
      'title' => st('What is a Card?'),
      'body' => st('<p>A Card can only be seen as part of another page. Place them individually as "Existing content" Blocks, or grouped as in a View.</p><p><a href="https://docs.backdropcms.org/documentation/creating-and-editing-content">Learn more about Cards</a></p>'),
    ),
    'card3-organize.png' => array(
      'title' => st('Organize your content'),
      'body' => st('<p>Backdrop CMS includes three pre-defined types of content: Pages, Posts, and Cards. Custom content types can also be added.</p><p><a href="https://docs.backdropcms.org/documentation/content-types">Learn more about content types</a></p>'),
    ),
  );

  foreach ($cards as $image_filename => $info) {
    $image_url = BACKDROP_ROOT . '/' . backdrop_get_path('profile', 'standard') . '/images/' . $image_filename;
    $moved_file = file_unmanaged_copy($image_url, $field_image_dir);

    $file = entity_create('file', array(
      'filename' => $image_filename,
      'uri' => $moved_file,
      'uid' => 1,
    ));

    $file->save();
    $card = new Node(
    array(
      'title' => $info['title'],
      'body' => array(
        LANGUAGE_NONE => array(
          array(
            'value' => $info['body'],
            'format' => 'filtered_html',
          ),
        ),
      ),
      'field_image' => array(
        LANGUAGE_NONE => array(
          array(
            'fid' => $file->fid,
            'filename' => $image_filename,
            'uri' => 'public://field/image/' . $image_filename,
            'filemime' => 'image/jpeg',
            'status' => 0,
          ),
        ),
      ),
      'uid' => 1,
      'status' => 1,
      'promote' => 1,
      'type' => 'card',
    )
    );

    $card->save();
  }

  // Modify the default promoted view to exclude cards.
  $promoted_view = views_get_view('promoted');
  $promoted_view->display['default']->display_options['filters']['type'] = array(
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'operator' => 'not in',
    'value' => array('card' => 'card'),
  );
  $promoted_view->save();

  // Enable default permissions for system roles.
  $filtered_html_permission = filter_permission_name($filtered_html_format);
  $anonymous_permissions = array(
    'access content',
    'access comments',
    $filtered_html_permission,
  );
  $authenticated_permissions = array(
    'access content',
    'access comments',
    'post comments',
    'skip comment approval',
    'upload editor images',
    $filtered_html_permission,
  );
  user_role_grant_permissions(BACKDROP_ANONYMOUS_ROLE, $anonymous_permissions);
  user_role_grant_permissions(BACKDROP_AUTHENTICATED_ROLE, $authenticated_permissions);

  // Create a default editor role, for users who need to be able to edit
  // content, but do not need to access advanced admin features.
  $editor_role = new stdClass();
  $editor_role->name = 'editor';
  $editor_role->label = 'Editor';
  $editor_role->description = 'Can edit most content on the site, but cannot modify site configuration settings.';
  $editor_role->weight = 2;
  user_role_save($editor_role);

  $editor_permissions = array(
    'view own unpublished content',
    'view any unpublished content',
    'view revisions',
    'revert revisions',
    'delete revisions',
    'create page content',
    'edit own page content',
    'edit any page content',
    'delete own page content',
    'create post content',
    'edit own post content',
    'edit any post content',
    'delete own post content',
    'create card content',
    'edit own card content',
    'edit any card content',
    'delete own card content',
    'view hidden paths',
    'access dashboard',
    'view the administration theme',
    'access administration bar',
    'access content overview',
    'access administration pages',
    'access site in maintenance mode',
    'flush caches',
    'edit terms in tags',
    'delete terms in tags',
    'administer taxonomy',
    'administer nodes',
    'search content',
    'use advanced search',
    $filtered_html_permission,
  );
  user_role_grant_permissions('editor', $editor_permissions);

  // Create a default role for site administrators, with all available
  // permissions assigned.
  $admin_role = new stdClass();
  $admin_role->name = 'administrator';
  $admin_role->label = 'Administrator';
  $admin_role->description = 'Can manage content and configuration, including the ability to assign roles.';
  $admin_role->weight = 3;
  $admin_role->permissions = array_keys(module_invoke_all('permission'));
  user_role_save($admin_role);
  // Set this as the administrator role.
  config_set('system.core', 'user_admin_role', $admin_role->name);

  // Assign the "Administrator" role to user 1, and make sure that generation of
  // automatic path alias is enabled.
  $admin_user = user_load(1);
  $admin_user->roles[] = $admin_role->name;
  $admin_user->path['auto'] = TRUE;
  user_save($admin_user);

  // Create a Home link in the main menu.
  $item = array(
    'link_title' => st('Home'),
    'link_path' => '<front>',
    'menu_name' => 'main-menu',
    'weight' => -1,
  );
  menu_link_save($item);

  // Create a login link in the account menu.
  $item = array(
    'link_title' => st('Login'),
    'link_path' => 'user/login',
    'menu_name' => 'user-menu',
    'weight' => -1,
  );
  menu_link_save($item);

  // Update the menu router information.
  menu_rebuild();

  // Enable the admin theme.
  db_update('system')
    ->fields(array('status' => 1))
    ->condition('type', 'theme')
    ->condition('name', 'seven')
    ->execute();
  config_set('system.core', 'admin_theme', 'seven');
  config_set('system.core', 'node_admin_theme', '1');

  // Enable the page cache and aggregation.
  config_set('system.core', 'preprocess_css', '1');
  config_set('system.core', 'preprocess_js', '1');
  config_set('system.core', 'cache', '1');
}