---
tags: Tripal v4 Team
---
# Tripal 4 Upgrade Notes
> This document is indended to quickly save upgrade information. During the process of upgrading Tripal Core we're going to place useful information here until it can be more formally written up into docs.
## tripal_set_message() and tripal_report_error()
These functions have been upgraded and thus can be used as is. However, the new way is use a logger service as shown below.
```php
$logger = \Drupal::service('tripal.logger');
$logger->notice('Hello world');
$logger->info('Hello world');
$logger->warning('Hello world');
$logger->error('Hello world');
$logger->debug('Hello world');
```
## drupal_set_message()
Changelog: https://www.drupal.org/node/2774931
```php
use Drupal\Core\Messenger\MessengerInterface;
// if not set by constructor...
$this->messenger = \Drupal::messenger();
// Add specific type of message within classes.
$this->messenger->addMessage('Hello world', 'custom');
$this->messenger->addError('Hello world');
$this->messenger->addStatus('Hello world');
$this->messenger->addWarning('Hello world');
// In procedural code:
$messenger = \Drupal::messenger();
$messenger->addMessage('Hello world', 'custom');
$messenger->addError('Hello world');
$messenger->addStatus('Hello world');
$messenger->addWarning('Hello world');
```
## drupal_add_js() and drupal_add_css()
Changelog: https://www.drupal.org/node/2169605
```php
// Example, to attach your library to a form (Form controller see routing):
$form['#attached']['library'][] = 'yourmodule/create-pallets';
# Library definitions in module.libraries.yml
create-pallets:
version: 1.x
header: false
js:
js/create-pallets.js: {}
// Passing PHP data/values to your script.
$form['#attached']['library'][] = 'yourmodule/create-pallets';
$form['#attached']['drupalSettings']['yourmodule']['colour_scheme'] = $color_scheme;
// Access data/values in your script:
var colour_scheme = drupalSettings.yourmodule.colour_scheme;
console.log(colour_scheme);
```
## variable_get(), variable_set(), variable_del()
Changelog:
How to upgrade D7 variables to D8's state system
https://www.drupal.org/docs/upgrading-and-converting-drupal-7-modules/step-5-how-to-upgrade-d7-variables-to-d8s-state
It is important to uninstall then install the module each time you add/test another variable.
## module_invoke_all()
Changelog: https://www.drupal.org/node/1894902
```php
In D7:
module_invoke_all(hook name);
where hook name is the name of the hook to invoke
In D8:
\Drupal::moduleHandler()->invokeAll(hook name, $args = array());
```
## module.info - module.info.yml
Changelog: https://www.drupal.org/node/1935708
Let Drupal know about your module.
See this step by step guide to converting your module.info to module.info.yml.
https://www.drupal.org/docs/converting-drupal-7-modules-to-drupal-8/step-1-convert-mymoduleinfo-to-mymoduleinfoyml
## hook_menu()
Changelog: https://www.drupal.org/node/1800686
Routes are responsible for associating a path to controllers. Converting Drupal 7 hook_menu() items to Drupal 8 APIs should start with defining the routes for the items.
Introductory Drupal 8 Routes:
https://www.drupal.org/node/2116767
Structures of Routes:
https://www.drupal.org/docs/drupal-apis/routing-system/structure-of-routes
D7 - D8 upgrade tutorial: Convert hook_menu to Drupal 8 APIs:
https://www.drupal.org/docs/converting-drupal-7-modules-to-drupal-8/d7-to-d8-upgrade-tutorial-convert-hook_menu-and-hook
# hook_permissions()
Changelog: https://www.drupal.org/node/2311427
Permissions are now defined in $module.permissions.yml file instead of using hook_permission() and there is scarce information about what each permission
options means other than the following.
**machine name** of the permission required to visit the URL.
**title** is the human readable information appearing in the Permissions page.
When "**restrict access**" is set to "true" a warning about site security will be displayed on the Permissions page.
**description** is optional
An example:
```php
# In your module.permissions.yml
view tripald3 json:
title: 'View Tripal D3 JSON'
description: 'Required for anyone wanting to view a Tripal D3 diagram'
restricted access: TRUE
# To use, in your module.routing.yml set the _permission: to the machine
# name of the permission.
tripald3.tree:
path: '/ajax/tripal/d3-json/relationships/{base_table}/{id}'
defaults:
_title: 'Tripal D3 JSON API: Stock Relationship Object'
_controller: '\Drupal\tripald3\Controller\TripalD3RelationshipJsonController::response'
requirements:
_permission: 'view tripald3 json'
```
# PHP Unit Browser Test
Drupal PHP Unit Test
https://www.drupal.org/docs/automated-testing/phpunit-in-drupal/phpunit-browser-test-tutorial
# Configuration Schema
Used in your configuration YML files
https://www.drupal.org/docs/drupal-apis/configuration-api/configuration-schemametadata
An example:
https://www.drupal.org/docs/drupal-apis/configuration-api/creating-a-configuration-entity-type
# AJAX Forms
https://www.drupal.org/docs/drupal-apis/javascript-api/ajax-forms