Newer
Older

Ben Mullins
committed
<?php

Tim Plunkett
committed
/**
* @file
* Contains install and update functions for Project Browser.
*/

Adam G-H
committed
use Drupal\Core\Recipe\Recipe;

Ben Mullins
committed

Ben Mullins
committed
/**
* Implements hook_install().
*

Ben Mullins
committed
* Populates the project_browser_projects using a fixture with PHP serialized

Ben Mullins
committed
* items.
*/
function project_browser_install() {

Adam G-H
committed
if (class_exists(Recipe::class)) {
$config = \Drupal::configFactory()
->getEditable('project_browser.admin_settings');
$enabled_sources = $config->get('enabled_sources');
$enabled_sources[] = 'recipes';
$config->set('enabled_sources', $enabled_sources)->save();
}

Ben Mullins
committed
}

Fran Garcia-Linares
committed
* Implements hook_update_last_removed().

Fran Garcia-Linares
committed
function project_browser_update_last_removed() {
return 9017;

Srishti Bankar
committed
}

Narendra Singh Rathore
committed
/**
* Implements hook_update_N().
*

Fran Garcia-Linares
committed
* Remove disable_add_new_module setting.

Narendra Singh Rathore
committed
*/

Fran Garcia-Linares
committed
function project_browser_update_9018() {

Narendra Singh Rathore
committed
$config_factory = \Drupal::configFactory();
$config_factory->getEditable('project_browser.admin_settings')

Fran Garcia-Linares
committed
->clear('disable_add_new_module')

Narendra Singh Rathore
committed
->save(TRUE);
}
/**
* Implements hook_update_N().
*

Fran Garcia-Linares
committed
* Remove the Drupal.org(Mock API) setting and tables.

Fran Garcia-Linares
committed
function project_browser_update_9019() {
// Remove the mock from the enabled_sources, if present.
$config = \Drupal::configFactory()->getEditable('project_browser.admin_settings');
$enabled_sources = $config->get('enabled_sources');
if (($key = array_search('drupalorg_mockapi', $enabled_sources)) !== FALSE) {
unset($enabled_sources[$key]);
$enabled_sources = array_values($enabled_sources);
$config->set('enabled_sources', $enabled_sources)->save();
}

Fran Garcia-Linares
committed
// And remove the tables.
$schema = \Drupal::database()->schema();
$tables_to_drop = ['project_browser_projects', 'project_browser_categories'];
foreach ($tables_to_drop as $table) {
if ($schema->tableExists($table)) {
$schema->dropTable($table);
}
}