Issue #1479454 by Hugo Wetterberg, galooph, dawehner, andypost, marcingy, heyrocker...
[project/drupal.git] / core / profiles / standard / standard.install
1 <?php
2 /**
3 * @file
4 * Install, update and uninstall functions for the standard installation profile.
5 */
6
7 /**
8 * Implements hook_install().
9 *
10 * Perform actions to set up the site for this profile.
11 *
12 * @see system_install()
13 */
14 function standard_install() {
15 // Enable Bartik theme and set it as default theme instead of Stark.
16 // @see system_install()
17 $default_theme = 'bartik';
18 variable_set('theme_default', $default_theme);
19 theme_enable(array($default_theme));
20 theme_disable(array('stark'));
21
22 // Set front page to "node".
23 config('system.site')->set('page.front', 'node')->save();
24
25 // Insert default pre-defined node types into the database. For a complete
26 // list of available node type attributes, refer to the node type API
27 // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
28 $types = array(
29 array(
30 'type' => 'page',
31 'name' => st('Basic page'),
32 'base' => 'node_content',
33 'description' => st("Use <em>basic pages</em> for your static content, such as an 'About us' page."),
34 'custom' => 1,
35 'modified' => 1,
36 'locked' => 0,
37 ),
38 array(
39 'type' => 'article',
40 'name' => st('Article'),
41 'base' => 'node_content',
42 'description' => st('Use <em>articles</em> for time-sensitive content like news, press releases or blog posts.'),
43 'custom' => 1,
44 'modified' => 1,
45 'locked' => 0,
46 ),
47 );
48
49 foreach ($types as $type) {
50 $type = node_type_set_defaults($type);
51 node_type_save($type);
52 node_add_body_field($type);
53 }
54
55 // Insert default pre-defined RDF mapping into the database.
56 $rdf_mappings = array(
57 array(
58 'type' => 'node',
59 'bundle' => 'page',
60 'mapping' => array(
61 'rdftype' => array('foaf:Document'),
62 ),
63 ),
64 array(
65 'type' => 'node',
66 'bundle' => 'article',
67 'mapping' => array(
68 'field_image' => array(
69 'predicates' => array('og:image', 'rdfs:seeAlso'),
70 'type' => 'rel',
71 ),
72 'field_tags' => array(
73 'predicates' => array('dc:subject'),
74 'type' => 'rel',
75 ),
76 ),
77 ),
78 );
79 foreach ($rdf_mappings as $rdf_mapping) {
80 rdf_mapping_save($rdf_mapping);
81 }
82
83 // Default "Basic page" to not be promoted and have comments disabled.
84 variable_set('node_options_page', array('status'));
85 variable_set('comment_page', COMMENT_NODE_HIDDEN);
86
87 // Don't display date and author information for "Basic page" nodes by default.
88 variable_set('node_submitted_page', FALSE);
89
90 // Allow visitor account creation with administrative approval.
91 $user_settings = config('user.settings');
92 $user_settings->set('register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save();
93
94 // Create a default vocabulary named "Tags", enabled for the 'article' content type.
95 $description = st('Use tags to group articles on similar topics into categories.');
96 $help = st('Enter a comma-separated list of words to describe your content.');
97 $vocabulary = entity_create('taxonomy_vocabulary', array(
98 'name' => st('Tags'),
99 'description' => $description,
100 'vid' => 'tags',
101 'langcode' => language_default()->langcode,
102 'help' => $help,
103 ));
104 taxonomy_vocabulary_save($vocabulary);
105
106 $field = array(
107 'field_name' => 'field_' . $vocabulary->id(),
108 'type' => 'taxonomy_term_reference',
109 // Set cardinality to unlimited for tagging.
110 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
111 'settings' => array(
112 'allowed_values' => array(
113 array(
114 'vocabulary' => $vocabulary->id(),
115 'parent' => 0,
116 ),
117 ),
118 ),
119 );
120 field_create_field($field);
121
122 $instance = array(
123 'field_name' => 'field_' . $vocabulary->id(),
124 'entity_type' => 'node',
125 'label' => 'Tags',
126 'bundle' => 'article',
127 'description' => $vocabulary->help,
128 'widget' => array(
129 'type' => 'taxonomy_autocomplete',
130 'weight' => -4,
131 ),
132 );
133 field_create_instance($instance);
134
135 // Assign display settings for the 'default' and 'teaser' view modes.
136 entity_get_display('node', 'article', 'default')
137 ->setComponent($instance['field_name'], array(
138 'type' => 'taxonomy_term_reference_link',
139 'weight' => 10,
140 ))
141 ->save();
142 entity_get_display('node', 'article', 'teaser')
143 ->setComponent($instance['field_name'], array(
144 'type' => 'taxonomy_term_reference_link',
145 'weight' => 10,
146 ))
147 ->save();
148
149 // Create an image field named "Image", enabled for the 'article' content type.
150 // Many of the following values will be defaulted, they're included here as an illustrative examples.
151 // See http://api.drupal.org/api/function/field_create_field/8
152
153 $field = array(
154 'field_name' => 'field_image',
155 'type' => 'image',
156 'cardinality' => 1,
157 'locked' => FALSE,
158 'indexes' => array('fid' => array('fid')),
159 'settings' => array(
160 'uri_scheme' => 'public',
161 'default_image' => FALSE,
162 ),
163 'storage' => array(
164 'type' => 'field_sql_storage',
165 'settings' => array(),
166 ),
167 );
168 field_create_field($field);
169
170
171 // Many of the following values will be defaulted, they're included here as an illustrative examples.
172 // See http://api.drupal.org/api/function/field_create_instance/8
173 $instance = array(
174 'field_name' => 'field_image',
175 'entity_type' => 'node',
176 'label' => 'Image',
177 'bundle' => 'article',
178 'description' => st('Upload an image to go with this article.'),
179 'required' => FALSE,
180
181 'settings' => array(
182 'file_directory' => 'field/image',
183 'file_extensions' => 'png gif jpg jpeg',
184 'max_filesize' => '',
185 'max_resolution' => '',
186 'min_resolution' => '',
187 'alt_field' => TRUE,
188 'title_field' => '',
189 ),
190
191 'widget' => array(
192 'type' => 'image_image',
193 'settings' => array(
194 'progress_indicator' => 'throbber',
195 'preview_image_style' => 'thumbnail',
196 ),
197 'weight' => -1,
198 ),
199 );
200 field_create_instance($instance);
201
202 // Assign display settings for the 'default' and 'teaser' view modes.
203 entity_get_display('node', 'article', 'default')
204 ->setComponent($instance['field_name'], array(
205 'label' => 'hidden',
206 'type' => 'image',
207 'settings' => array('image_style' => 'large', 'image_link' => ''),
208 'weight' => -1,
209 ))
210 ->save();
211 entity_get_display('node', 'article', 'teaser')
212 ->setComponent($instance['field_name'], array(
213 'label' => 'hidden',
214 'type' => 'image',
215 'settings' => array('image_style' => 'medium', 'image_link' => 'content'),
216 'weight' => -1,
217 ))
218 ->save();
219
220 // Create user picture field.
221 module_load_install('user');
222 user_install_picture_field();
223
224 // Enable default permissions for system roles.
225 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access content', 'access comments'));
226 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access content', 'access comments', 'post comments', 'skip comment approval'));
227
228 // Enable all permissions for the administrator role.
229 user_role_grant_permissions('administrator', array_keys(module_invoke_all('permission')));
230 // Set this as the administrator role.
231 $user_settings->set('admin_role', 'administrator')->save();
232
233 // Assign user 1 the "administrator" role.
234 db_insert('users_roles')
235 ->fields(array('uid' => 1, 'rid' => 'administrator'))
236 ->execute();
237
238 // Create a Home link in the main menu.
239 $item = array(
240 'link_title' => st('Home'),
241 'link_path' => '<front>',
242 'menu_name' => 'main',
243 );
244 menu_link_save($item);
245
246 // Enable the Contact link in the footer menu.
247 menu_link_maintain('system', 'enable', 'contact');
248 user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access site-wide contact form'));
249 user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access site-wide contact form'));
250
251 // Populate the default shortcut set.
252 $shortcut_set = shortcut_set_load(SHORTCUT_DEFAULT_SET_NAME);
253 $shortcut_set->links[] = array(
254 'link_path' => 'node/add',
255 'link_title' => st('Add content'),
256 'weight' => -20,
257 );
258 $shortcut_set->links[] = array(
259 'link_path' => 'admin/content',
260 'link_title' => st('Find content'),
261 'weight' => -19,
262 );
263 shortcut_set_save($shortcut_set);
264
265 // Enable the admin theme.
266 theme_enable(array('seven'));
267 config('system.theme')->set('admin', 'seven')->save();
268 variable_set('node_admin_theme', '1');
269 }