added features

This commit is contained in:
Bachir Soussi Chiadmi
2016-09-06 12:46:13 +02:00
parent f192bc2ffa
commit c6cff46234
109 changed files with 17546 additions and 0 deletions
@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
@@ -0,0 +1,13 @@
Configuration Update Manager project
------------------------------------
The Configuration Update Manager project consists of two modules:
Configuration Update Base: A base module providing functionality related to
updating and computing differences between configuration versions. No
user interface; used by other modules such as Features.
Configuration Update Reports (in the config_ui sub-directory of this project):
Adds an updates report and revert functionality to configuration management.
Depends on Configuration Update Base. For more information, see the
README.txt file in the subdirectory.
@@ -0,0 +1,12 @@
name: Configuration Update Base
type: module
description: 'Provides basic revert and update functionality for other modules'
# core: 8.x
dependencies:
- config
# Information added by Drupal.org packaging script on 2016-03-08
version: '8.x-1.1'
core: '8.x'
project: 'config_update'
datestamp: 1457466840
@@ -0,0 +1,21 @@
<?php
/**
* @file
* Configuration Update Base module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function config_update_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.config_update':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Configuration Update Base module provides functionality that other modules can use, related to updating and computing differences between configuration versions. This module does not provide any end-user functionality itself.') . '</p>';
return $output;
}
}
@@ -0,0 +1,20 @@
services:
config_update.config_diff:
class: Drupal\config_update\ConfigDiffer
arguments: ['@string_translation']
config_update.config_list:
class: Drupal\config_update\ConfigLister
arguments: ['@entity.manager', '@config.storage', '@config_update.extension_storage', '@config_update.extension_optional_storage']
config_update.config_update:
class: Drupal\config_update\ConfigReverter
arguments: ['@entity.manager', '@config.storage', '@config_update.extension_storage', '@config_update.extension_optional_storage', '@config.factory', '@event_dispatcher']
config_update.extension_storage:
class: Drupal\Core\Config\ExtensionInstallStorage
arguments: ['@config.storage']
config_update.extension_optional_storage:
class: Drupal\Core\Config\ExtensionInstallStorage
arguments: ['@config.storage', 'config/optional']
@@ -0,0 +1,162 @@
Configuration Update Reports module
-----------------------------------
CONTENTS OF THIS README FILE
- Introduction
- Installation
- Generating reports in the user interface
- Generating reports using Drush commands
- Important notes *** Be sure to read this section ***
INTRODUCTION
This module provides a report that allows you to see the differences between the
default configuration items provided by the current versions of your installed
modules, themes, and install profile, and the active configuration of your
site. From this report, you can also import new configuration provided by
updates, and revert your site configuration to the provided values.
The main use case is: You update a module, and it has either changed default
configuration that it provides, or added new default configuration items that
you didn't get when you first installed the module. You want to be able to
import the new items, view the differences between the active site configuration
and the changed configuration, and possibly "revert" (or it may be an update) to
the newly-provided default configuration.
INSTALLATION
Install the module in the normal way for Drupal modules. The only dependencies
are the Configuration Manager module (Drupal core), and the Configuration Update
Base module (part of this same project download).
GENERATING REPORTS IN THE USER INTERFACE
You can generate configuration reports at Administration >> Configuration >>
Development >> Configuration management >> Update report (path:
admin/config/development/configuration/report ).
You can generate a report for a particular type of configuration object, such as
Actions, Tours, Views, etc. Or, you can generate a report for an installed
module, theme, or install profile. Finally, you can generate a report that
contains all configuration in one report.
The report has three sections, depending on what type you choose:
1. Missing configuration items: Configuration items that are provided as
defaults by your currently-installed modules, themes, and install profile
that are missing from your active site configuration.
Any items listed here can be imported into your site.
2. Added configuration items: Configuration items that you added to the site
(not provided by a currently-installed module, theme, or install
profile). This section is only shown when you are running the report based on
a configuration type.
Items listed here can be exported, which is useful for developers or if you
want to keep your site configuration in a version control system.
3. Changed configuration items: Configuration items that are in your active site
configuration that differ from the same item currently being provided by an
installed module, theme, or install profile.
You can export these items, see the differences between what is on your site
and what the module/theme/profile is currently providing, or "revert" to the
version currently being provided by the module/theme/profile in its default
configuration.
Note that the differences may be a bit hard to read, but hopefully they'll
give you the general idea of what has changed.
GENERATING REPORTS USING DRUSH COMMANDS
The reports detailed in the previous section can also be generated, in pieces,
using Drush commands (https://drupal.org/project/drush):
drush config-list-types (clt)
Lists all the config types on your system. Reports can be run for
'system.simple' (simple configuration), and 'system.all' (all types), in
addition to the types listed by this command.
drush config-added-report (cra)
drush config-missing-report (crm)
drush config-different-report (crd)
Run config reports (see below).
drush config-diff (cfd)
Show config differences for one item between active and imported (see below).
The report commands run reports that tell what config has been added, is
missing, or is different between your active site configuration and the imported
default configuration from config/install directories of your installed profile,
modules, and themes.
For each report except "added", the first argument is one of:
- type: Runs the report for a configuration type; use drush config-list-types to
list them.
- module: Runs the report for an installed module.
- theme: Runs the report for an installed theme.
- profile: Runs the report for the install profile.
The second argument for reports is the machine name of the configuration type,
module, theme, or install profile you want to run the report for. For the
"added" report, this is the only argument, as the added report is always by
configuration type.
These are the same as the reports you get in the UI, which is described above;
the only difference is that in Drush the report is separated into pieces.
Once you have found a configuration item with differences, you can view the
differences using the config-diff command. This is a normalized/formatted diff
like in the UI of this module, so see above for details.
Drush examples:
drush clt
drush crm module node
drush cra block
drush crd theme bartik
drush crd type system.all
drush crd type system.simple
drush crd profile standard
drush cfd block.block.bartik_search
Once you have figured out which configuration items are added, missing, or
different, you can:
- Export them - see drush config-export.
- Import missing configuration or revert to provided default values. To do this:
(1) Locate the configuration file in the install profile, module, or theme
config/install directory.
(2) Copy this file to your configuration staging directory.
(3) Run drush config-import. You might want to use the --preview option to see
what differences you are about to import, before running the import, or
use the drush config-diff command to look at individual differences.
IMPORTANT NOTES
Here are some notes about how this module functions:
* This module is always looking at the base configuration items, without
overrides (from settings.php, for example) or translations.
* It is possible for an install profile on a site to provide configuration that
overrides configuration from a module or theme. The install profile version
always takes precedence. As an example, consider the case where module Foo
provides a configuration item called foo.settings, and install profile Bar
overrides this with its own file. Any reports that include foo.settings will
be based on the differences between your site's active configuration and the
version in the install profile. This is not usually a problem, but it can be
confusing if you're looking at the Foo module report. The foo.settings item
will be present, but the differences reported will be between the install
profile's version and your site's active configuration, not the differences
between the Foo module version and your site's active configuration.
@@ -0,0 +1,232 @@
<?php
/**
* @file
* Drush commands for the Configuration Update Reports module.
*/
use Drupal\Component\Diff\DiffFormatter;
/**
* Implements hook_drush_command().
*/
function config_update_ui_drush_command() {
$items = [];
$items['config-list-types'] = [
'description' => 'List config types',
'aliases' => ['clt'],
'core' => ['8+'],
'outputformat' => [
'default' => 'list',
],
];
$items['config-added-report'] = [
'description' => 'Display a list of config items that did not come from your installed modules, themes, or install profile',
'arguments' => [
'name' => 'The type of config to report on. See config-list-types to list them. You can also use system.all for all types, or system.simple for simple config.',
],
'required-arguments' => 1,
'examples' => [
'drush config-added-report action' => 'Displays the added config report for action config.',
],
'aliases' => ['cra'],
'core' => ['8+'],
'outputformat' => [
'default' => 'list',
],
];
$items['config-missing-report'] = [
'description' => 'Display a list of config items from your installed modules, themes, or install profile that are not currently in your active config',
'arguments' => [
'type' => 'Run the report for: module, theme, profile, or "type" for config entity type.',
'name' => 'The machine name of the module, theme, etc. to report on. See config-list-types to list types for config entities; you can also use system.all for all types, or system.simple for simple config.',
],
'required-arguments' => 2,
'examples' => [
'drush config-missing-report type action' => 'Displays the missing config report for action config.',
],
'aliases' => ['crm'],
'core' => ['8+'],
'outputformat' => [
'default' => 'list',
],
];
$items['config-inactive-report'] = [
'description' => 'Display a list of optional config items from your installed modules, themes, or install profile that are not currently in your active config',
'arguments' => [
'type' => 'Run the report for: module, theme, profile, or "type" for config entity type.',
'name' => 'The machine name of the module, theme, etc. to report on. See config-list-types to list types for config entities; you can also use system.all for all types, or system.simple for simple config.',
],
'required-arguments' => 2,
'examples' => [
'drush config-inactive-report type action' => 'Displays the inactive config report for action config.',
],
'aliases' => ['cri'],
'core' => ['8+'],
'outputformat' => [
'default' => 'list',
],
];
$items['config-different-report'] = [
'description' => 'Display a list of config items that differ from the versions imported from your installed modules, themes, or install profile. See config-diff to show what the differences are.',
'arguments' => [
'type' => 'Run the report for: module, theme, profile, or "type" for config entity type.',
'name' => 'The machine name of the module, theme, etc. to report on. See config-list-types to list types for config entities; you can also use system.all for all types, or system.simple for simple config.',
],
'required-arguments' => 2,
'examples' => [
'drush config-different-report type action' => 'Displays the differing config report for action config.',
],
'drupal dependencies' => ['config_update_ui'],
'aliases' => ['crd'],
'core' => ['8+'],
'outputformat' => [
'default' => 'list',
],
];
$items['config-diff'] = [
'description' => 'Display line-by-line differences for one config item between your active config and the version currently being provided by an installed module, theme, or install profile',
'arguments' => [
'name' => 'The config item to diff. See config-different-report to list config items that are different.',
],
'required-arguments' => 1,
'examples' => [
'drush config-diff block.block.bartik_search' => 'Displays the config differences for the search block in the Bartik theme.',
],
'aliases' => ['cfd'],
'core' => ['8+'],
];
return $items;
}
/**
* Lists available config types.
*/
function drush_config_update_ui_config_list_types() {
$list = [];
$definitions = \Drupal::service('config_update.config_list')->listTypes();
return array_keys($definitions);
}
/**
* Runs the config added report.
*
* @param string $name
* Type of config to report on.
*/
function drush_config_update_ui_config_added_report($name) {
list($active_list, $install_list, $optional_list) = \Drupal::service('config_update.config_list')->listConfig('type', $name);
$added = array_diff($active_list, $install_list, $optional_list);
if (!count($added)) {
drush_print(dt('No added config'), 0, STDERR);
}
sort($added);
return $added;
}
/**
* Runs the config missing report.
*
* @param string $type
* Type of report to run: 'type', 'module', 'theme', or 'profile'.
* @param string $name
* Machine name of item to report on.
*/
function drush_config_update_ui_config_missing_report($type, $name) {
list($active_list, $install_list, $optional_list) = \Drupal::service('config_update.config_list')->listConfig($type, $name);
$missing = array_diff($install_list, $active_list);
if (!count($missing)) {
drush_print(dt('No missing config'), 0, STDERR);
}
sort($missing);
return $missing;
}
/**
* Runs the config inactive report.
*
* @param string $type
* Type of report to run: 'type', 'module', 'theme', or 'profile'.
* @param string $name
* Machine name of item to report on.
*/
function drush_config_update_ui_config_inactive_report($type, $name) {
list($active_list, $install_list, $optional_list) = \Drupal::service('config_update.config_list')->listConfig($type, $name);
$missing = array_diff($optional_list, $active_list);
if (!count($missing)) {
drush_print(dt('No inactive config'), 0, STDERR);
}
sort($missing);
return $missing;
}
/**
* Runs the config different report.
*
* @param string $type
* Type of report to run: 'type', 'module', 'theme', or 'profile'.
* @param string $name
* Machine name of item to report on.
*/
function drush_config_update_ui_config_different_report($type, $name) {
list($active_list, $install_list, $optional_list) = \Drupal::service('config_update.config_list')->listConfig($type, $name);
$reverter = \Drupal::service('config_update.config_update');
$differ = \Drupal::service('config_update.config_diff');
$added = array_diff($active_list, $install_list, $optional_list);
$both = array_diff($active_list, $added);
$different = [];
foreach ($both as $name) {
$active = $reverter->getFromActive('', $name);
$extension = $reverter->getFromExtension('', $name);
if (!$differ->same($active, $extension)) {
$different[] = $name;
}
}
if (!count($different)) {
drush_print(dt('No different config'), 0, STDERR);
}
sort($different);
return $different;
}
/**
* Runs the drush config-diff command.
*
* @param string $name
* Config item to diff.
*/
function drush_config_update_ui_config_diff($name) {
$reverter = \Drupal::service('config_update.config_update');
$differ = \Drupal::service('config_update.config_diff');
$formatter = new DiffFormatter();
$extension = $reverter->getFromExtension('', $name);
$active = $reverter->getFromActive('', $name);
if ($extension && !$active) {
$diff = $differ->diff($extension, $active);
drush_print($formatter->format($diff));
}
else {
drush_print(dt('Config is missing, cannot diff'), 0, STDERR);
}
}
@@ -0,0 +1,14 @@
name: Configuration Update Reports
type: module
description: 'Adds an updates report and revert functionality to configuration management'
# core: 8.x
configure: config_update.report
dependencies:
- config_update
- config
# Information added by Drupal.org packaging script on 2016-03-08
version: '8.x-1.1'
core: '8.x'
project: 'config_update'
datestamp: 1457466840
@@ -0,0 +1,5 @@
report_css:
version: 1.x
css:
theme:
css/config_update_ui.report.css: {}
@@ -0,0 +1,5 @@
config_update_ui.report:
route_name: config_update_ui.report
title: 'Updates report'
base_route: config.sync
weight: 1000
@@ -0,0 +1,37 @@
<?php
/**
* @file
* Configuration Update Reports module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function config_update_ui_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.config_update_ui':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Configuration Update Reports module provides a report that allows you to see the differences between the default configuration provided by the current versions of your installed modules, themes, and install profile, and the active configuration of your site. From this report, you can also import new configuration provided by updates, and revert your active configuration to the provided default values.') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Checking for configuration differences') . '</dd>';
$output .= '<dd>' . t('The <a href=":report">Updates report</a> shows you configuration that differs between your site\'s active configuration and the installed modules, themes, and install profile. Choose a particular configuration type (or All), or run the report for a particular module, theme, or your install profile.', [':report' => Url::fromRoute('config_update_ui.report')->toString()]) . '</dd>';
$output .= '</dl>';
return $output;
case 'config_update_ui.report':
$output = '';
$output .= '<p>' . t('This report shows which default configuration items provided by the current versions of your installed modules, themes, and install profile differ from the active configuration of your site. You can generate the report for all configuration of a certain type, or for a particular installed module, theme, or your install profile.') . '</p>';
$output .= '<p>' . t('Some configuration provided by modules has dependencies, and is only added to your system when all the dependencies are satisfied. This is known as <em>optional</em> configuration.') . '</p>';
$output .= '<p>' . t('Differences, including missing and added configuration, can be due to either an updated module or theme providing different configuration from when you installed it, or to changes made by site administrators. This report does not differentiate between these two sources for differences, and note that an install profile can also silently override module/theme configuration. Overrides (such as those in your settings.php file) and translations are not considered when looking at differences.') . '</p>';
return $output;
case 'config_update_ui.diff':
return '<p>' . t('Most configuration is organized into a hierarchy of settings; at a minimum, it is a one-level hierarchy where each setting has a name and a value, and the hierarchy comes in when some of the settings have multiple components.') . '</p><p>' . t('Configuration items are normalized and formatted before computing differences. The normalization step alphabetizes the components at each level of the hierarchy, and removes a few components whose differences should be ignored, such as the UUID. The formatting step shows the full hierarchy of each configuration value with :: separators for the hierarchy levels, and a : separator between the lowest-level setting name and the value, so that in a line-by-line diff you can always see which values are actually different. Green lines with + signs have been added, and yellow lines with - signs have been removed.') . '</p><p>' . t('Note that differences are considering the base configuration, without overrides from your settings.php file, or translations.') . '</p>';
}
}
@@ -0,0 +1,8 @@
view config updates report:
title: 'View configuration updates report'
revert configuration:
title: 'Revert any configuration'
restrict access: true
delete configuration:
title: 'Delete any configuration'
restrict access: true
@@ -0,0 +1,45 @@
config_update_ui.report:
path: '/admin/config/development/configuration/report/{report_type}/{name}'
defaults:
_controller: '\Drupal\config_update_ui\Controller\ConfigUpdateController::report'
_title: 'Updates report'
report_type: NULL
name: NULL
requirements:
_permission: 'view config updates report'
config_update_ui.import:
path: '/admin/config/development/configuration/report/import/{config_type}/{config_name}'
defaults:
_title: 'Import'
_controller: '\Drupal\config_update_ui\Controller\ConfigUpdateController::import'
config_type: NULL
config_name: NULL
requirements:
_permission: 'import configuration'
config_update_ui.diff:
path: '/admin/config/development/configuration/report/diff/{config_type}/{config_name}'
defaults:
_title: 'Differences'
_controller: '\Drupal\config_update_ui\Controller\ConfigUpdateController::diff'
config_type: NULL
config_name: NULL
requirements:
_permission: 'view config updates report'
config_update_ui.revert:
path: '/admin/config/development/configuration/report/revert/{config_type}/{config_name}'
defaults:
_title: 'Revert'
_form: '\Drupal\config_update_ui\Form\ConfigRevertConfirmForm'
requirements:
_permission: 'revert configuration'
config_update_ui.delete:
path: '/admin/config/development/configuration/report/delete/{config_type}/{config_name}'
defaults:
_title: 'Delete'
_form: '\Drupal\config_update_ui\Form\ConfigDeleteConfirmForm'
requirements:
_permission: 'delete configuration'
@@ -0,0 +1,13 @@
/**
* @file
* Styling for the Config Updates report.
*/
table.config-update-report {
margin-top: 2em;
}
table.config-update-report caption {
font-weight: bold;
font-size: 1.1em;
}
@@ -0,0 +1,576 @@
<?php
namespace Drupal\config_update_ui\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Diff\DiffFormatter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\config_update\ConfigDiffInterface;
use Drupal\config_update\ConfigListInterface;
use Drupal\config_update\ConfigRevertInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Returns responses for Configuration Revert module operations.
*/
class ConfigUpdateController extends ControllerBase {
/**
* The config differ.
*
* @var \Drupal\config_update\ConfigDiffInterface
*/
protected $configDiff;
/**
* The config lister.
*
* @var \Drupal\config_update\ConfigListInterface
*/
protected $configList;
/**
* The config reverter.
*
* @var \Drupal\config_update\ConfigRevertInterface
*/
protected $configRevert;
/**
* The diff formatter.
*
* @var \Drupal\Core\Diff\DiffFormatter
*/
protected $diffFormatter;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandlerInterface
*/
protected $themeHandler;
/**
* Constructs a ConfigUpdateController object.
*
* @param \Drupal\config_update\ConfigDiffInterface $config_diff
* The config differ.
* @param \Drupal\config_update\ConfigListInterface $config_list
* The config lister.
* @param \Drupal\config_update\ConfigRevertInterface $config_update
* The config reverter.
* @param \Drupal\Core\Diff\DiffFormatter $diff_formatter
* The diff formatter to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
*/
public function __construct(ConfigDiffInterface $config_diff, ConfigListInterface $config_list, ConfigRevertInterface $config_update, DiffFormatter $diff_formatter, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
$this->configDiff = $config_diff;
$this->configList = $config_list;
$this->configRevert = $config_update;
$this->diffFormatter = $diff_formatter;
$this->diffFormatter->show_header = FALSE;
$this->moduleHandler = $module_handler;
$this->themeHandler = $theme_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config_update.config_diff'),
$container->get('config_update.config_list'),
$container->get('config_update.config_update'),
$container->get('diff.formatter'),
$container->get('module_handler'),
$container->get('theme_handler')
);
}
/**
* Imports configuration from a module, theme, or profile.
*
* Configuration is assumed not to currently exist.
*
* @param string $config_type
* The type of configuration.
* @param string $config_name
* The name of the config item, without the prefix.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* Redirects to the updates report.
*/
public function import($config_type, $config_name) {
$this->configRevert->import($config_type, $config_name);
drupal_set_message($this->t('The configuration was imported.'));
return $this->redirect('config_update_ui.report');
}
/**
* Shows the diff between active and provided configuration.
*
* @param string $config_type
* The type of configuration.
* @param string $config_name
* The name of the config item, without the prefix.
*
* @return array
* Render array for page showing differences between them.
*/
public function diff($config_type, $config_name) {
$diff = $this->configDiff->diff(
$this->configRevert->getFromExtension($config_type, $config_name),
$this->configRevert->getFromActive($config_type, $config_name)
);
$build = [];
$definition = $this->configList->getType($config_type);
$config_type_label = ($definition) ? $definition->getLabel() : $this->t('Simple configuration');
$build['#title'] = $this->t('Config difference for @type @name', ['@type' => $config_type_label, '@name' => $config_name]);
$build['#attached']['library'][] = 'system/diff';
$build['diff'] = [
'#type' => 'table',
'#header' => [
['data' => $this->t('Source config'), 'colspan' => '2'],
['data' => $this->t('Site config'), 'colspan' => '2'],
],
'#rows' => $this->diffFormatter->format($diff),
'#attributes' => ['class' => ['diff']],
];
$url = new Url('config_update_ui.report');
$build['back'] = [
'#type' => 'link',
'#attributes' => [
'class' => [
'dialog-cancel',
],
],
'#title' => $this->t("Back to 'Updates report' page."),
'#url' => $url,
];
return $build;
}
/**
* Generates the config updates report.
*
* @param string $report_type
* (optional) Type of report to run:
* - type: Configuration entity type.
* - module: Module.
* - theme: Theme.
* - profile: Install profile.
* @param string $name
* (optional) Name of specific item to run report for (config entity type
* ID, module machine name, etc.). Ignored for profile.
*
* @return array
* Render array for report, with section at the top for selecting another
* report to run. If either $report_type or $name is missing, the report
* itself is not generated.
*/
public function report($report_type = NULL, $name = NULL) {
$links = $this->generateReportLinks();
$report = $this->generateReport($report_type, $name);
if (!$report) {
return $links;
}
// If there is a report, extract the title, put table of links in a
// details element, and add report to build.
$build = [];
$build['#title'] = $report['#title'];
unset($report['#title']);
$build['links_wrapper'] = [
'#type' => 'details',
'#title' => $this->t('Generate new report'),
'#children' => $links,
];
$build['report'] = $report;
$build['#attached']['library'][] = 'config_update/report_css';
return $build;
}
/**
* Generates the operations links for running individual reports.
*
* @return array
* Render array for the operations links for running reports.
*/
protected function generateReportLinks() {
// These links are put into an 'operations' render array element. They do
// not look good outside of tables. Also note that the array index in
// operations links is used as a class on the LI element. Some classes are
// special in the Seven CSS, such as "contextual", so avoid hitting these
// accidentally by prefixing.
$build = [];
$build['links'] = [
'#type' => 'table',
'#header' => [
$this->t('Report type'),
$this->t('Report on'),
],
'#rows' => [],
];
$definitions = $this->configList->listTypes();
$links = [];
foreach ($definitions as $entity_type => $definition) {
$links['type_' . $entity_type] = [
'title' => $definition->getLabel(),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'type', 'name' => $entity_type]),
];
}
uasort($links, [$this, 'sortLinks']);
$links = [
'type_all' => [
'title' => $this->t('All types'),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'type', 'name' => 'system.all']),
],
'type_system.simple' => [
'title' => $this->t('Simple configuration'),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'type', 'name' => 'system.simple']),
],
] + $links;
$build['links']['#rows'][] = [
$this->t('Configuration type'),
[
'data' => [
'#type' => 'operations',
'#links' => $links,
],
],
];
// Make a list of installed modules.
$profile = Settings::get('install_profile');
$modules = $this->moduleHandler->getModuleList();
$links = [];
foreach ($modules as $machine_name => $module) {
if ($machine_name != $profile) {
$links['module_' . $machine_name] = [
'title' => $this->moduleHandler->getName($machine_name),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'module', 'name' => $machine_name]),
];
}
}
uasort($links, [$this, 'sortLinks']);
$build['links']['#rows'][] = [
$this->t('Module'),
[
'data' => [
'#type' => 'operations',
'#links' => $links,
],
],
];
// Make a list of installed themes.
$themes = $this->themeHandler->listInfo();
$links = [];
foreach ($themes as $machine_name => $theme) {
$links['theme_' . $machine_name] = [
'title' => $this->themeHandler->getName($machine_name),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'theme', 'name' => $machine_name]),
];
}
uasort($links, [$this, 'sortLinks']);
$build['links']['#rows'][] = [
$this->t('Theme'),
[
'data' => [
'#type' => 'operations',
'#links' => $links,
],
],
];
// Profile is just one option.
$links = [];
$links['profile_' . $profile] = [
'title' => $this->moduleHandler->getName($profile),
'url' => Url::fromRoute('config_update_ui.report', ['report_type' => 'profile']),
];
$build['links']['#rows'][] = [
$this->t('Installation profile'),
[
'data' => [
'#type' => 'operations',
'#links' => $links,
],
],
];
return $build;
}
/**
* Generates a report about config updates.
*
* @param string $report_type
* Type of report to generate: 'type', 'module', 'theme', or 'profile'.
* @param string $value
* Machine name of a configuration type, module, or theme to generate the
* report for. Ignored for profile, since that uses the active profile.
*
* @return array
* Render array for the updates report. Empty if invalid or missing
* report type or value.
*/
protected function generateReport($report_type, $value) {
// Figure out what to name the report, and incidentally, validate that
// $value exists for this type of report.
switch ($report_type) {
case 'type':
if ($value == 'system.all') {
$label = $this->t('All configuration');
}
elseif ($value == 'system.simple') {
$label = $this->t('Simple configuration');
}
else {
$definition = $this->configList->getType($value);
if (!$definition) {
return NULL;
}
$label = $this->t('@name configuration', ['@name' => $definition->getLabel()]);
}
break;
case 'module':
$list = $this->moduleHandler->getModuleList();
if (!isset($list[$value])) {
return NULL;
}
$label = $this->t('@name module', ['@name' => $this->moduleHandler->getName($value)]);
break;
case 'theme':
$list = $this->themeHandler->listInfo();
if (!isset($list[$value])) {
return NULL;
}
$label = $this->t('@name theme', ['@name' => $this->themeHandler->getName($value)]);
break;
case 'profile':
$profile = Settings::get('install_profile');
$label = $this->t('@name profile', ['@name' => $this->moduleHandler->getName($profile)]);
break;
default:
return NULL;
}
// List the active and extension-provided config.
list($active_list, $install_list, $optional_list) = $this->configList->listConfig($report_type, $value);
// Build the report.
$build = [];
$build['#title'] = $this->t('Configuration updates report for @label', ['@label' => $label]);
$build['report_header'] = ['#markup' => '<h3>' . $this->t('Updates report') . '</h3>'];
// List items missing from site.
$removed = array_diff($install_list, $active_list);
$build['removed'] = [
'#caption' => $this->t('Missing configuration items'),
'#empty' => $this->t('None: all provided configuration items are in your active configuration.'),
] + $this->makeReportTable($removed, 'extension', ['import']);
// List optional items that are not installed.
$inactive = array_diff($optional_list, $active_list);
$build['inactive'] = [
'#caption' => $this->t('Inactive optional items'),
'#empty' => $this->t('None: all optional configuration items are in your active configuration.'),
] + $this->makeReportTable($inactive, 'extension', ['import']);
// List items added to site, which only makes sense in the report for a
// config type.
$added = array_diff($active_list, $install_list, $optional_list);
if ($report_type == 'type') {
$build['added'] = [
'#caption' => $this->t('Added configuration items'),
'#empty' => $this->t('None: all active configuration items of this type were provided by modules, themes, or install profile.'),
] + $this->makeReportTable($added, 'active', ['export', 'delete']);
}
// For differences, we need to go through the array of config in both
// and see if each config item is the same or not.
$both = array_diff($active_list, $added);
$different = [];
foreach ($both as $name) {
if (!$this->configDiff->same(
$this->configRevert->getFromExtension('', $name),
$this->configRevert->getFromActive('', $name)
)) {
$different[] = $name;
}
}
$build['different'] = [
'#caption' => $this->t('Changed configuration items'),
'#empty' => $this->t('None: no active configuration items differ from their current provided versions.'),
] + $this->makeReportTable($different, 'active', ['diff', 'export', 'revert']);
return $build;
}
/**
* Builds a table for the report.
*
* @param string[] $names
* List of machine names of config items for the table.
* @param string $storage
* Config storage the items can be loaded from, either 'active' or
* 'extension'.
* @param string[] $actions
* Action links to include, one or more of:
* - diff
* - revert
* - export
* - import
* - delete
*
* @return array
* Render array for the table, not including the #empty and #prefix
* properties.
*/
protected function makeReportTable($names, $storage, $actions) {
$build = [];
$build['#type'] = 'table';
$build['#attributes'] = ['class' => ['config-update-report']];
$build['#header'] = [
'name' => [
'data' => $this->t('Machine name'),
],
'label' => [
'data' => $this->t('Label (if any)'),
'class' => [RESPONSIVE_PRIORITY_LOW],
],
'type' => [
'data' => $this->t('Type'),
'class' => [RESPONSIVE_PRIORITY_MEDIUM],
],
'operations' => [
'data' => $this->t('Operations'),
],
];
$build['#rows'] = [];
foreach ($names as $name) {
$row = [];
if ($storage == 'active') {
$config = $this->configRevert->getFromActive('', $name);
}
else {
$config = $this->configRevert->getFromExtension('', $name);
}
// Figure out what type of config it is, and get the ID.
$entity_type = $this->configList->getTypeNameByConfigName($name);
if (!$entity_type) {
// This is simple config.
$id = $name;
$type_label = $this->t('Simple configuration');
$entity_type = 'system.simple';
}
else {
$definition = $this->configList->getType($entity_type);
$id_key = $definition->getKey('id');
$id = $config[$id_key];
$type_label = $definition->getLabel();
}
$label = (isset($config['label'])) ? $config['label'] : '';
$row[] = $name;
$row[] = $label;
$row[] = $type_label;
$links = [];
$routes = [
'export' => 'config.export_single',
'import' => 'config_update_ui.import',
'diff' => 'config_update_ui.diff',
'revert' => 'config_update_ui.revert',
'delete' => 'config_update_ui.delete',
];
$titles = [
'export' => $this->t('Export'),
'import' => $this->t('Import from source'),
'diff' => $this->t('Show differences'),
'revert' => $this->t('Revert to source'),
'delete' => $this->t('Delete'),
];
foreach ($actions as $action) {
$links[$action] = [
'url' => Url::fromRoute($routes[$action], ['config_type' => $entity_type, 'config_name' => $id]),
'title' => $titles[$action],
];
}
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
],
];
$build['#rows'][] = $row;
}
return $build;
}
/**
* Compares links for uasort(), to sort by displayed link title.
*/
protected static function sortLinks($link1, $link2) {
$title1 = $link1['title'];
$title2 = $link2['title'];
if ($title1 == $title2) {
return 0;
}
return ($title1 < $title2) ? -1 : 1;
}
}
@@ -0,0 +1,143 @@
<?php
namespace Drupal\config_update_ui\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\config_update\ConfigListInterface;
use Drupal\config_update\ConfigRevertInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a confirmation form for deleting configuration.
*/
class ConfigDeleteConfirmForm extends ConfirmFormBase {
/**
* The type of config being deleted.
*
* @var string
*/
protected $type;
/**
* The name of the config item being deleted, without the prefix.
*
* @var string
*/
protected $name;
/**
* The config lister.
*
* @var \Drupal\config_update\ConfigListInterface
*/
protected $configList;
/**
* The config reverter.
*
* @var \Drupal\config_update\ConfigRevertInterface
*/
protected $configRevert;
/**
* Constructs a ConfigDeleteConfirmForm object.
*
* @param \Drupal\config_update\ConfigListInterface $config_list
* The config lister.
* @param \Drupal\config_update\ConfigRevertInterface $config_update
* The config reverter.
*/
public function __construct(ConfigListInterface $config_list, ConfigRevertInterface $config_update) {
$this->configList = $config_list;
$this->configRevert = $config_update;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config_update.config_list'),
$container->get('config_update.config_update')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_delete_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
if ($this->type == 'system.simple') {
$type_label = $this->t('Simple configuration');
}
else {
$definition = $this->configList->getType($this->type);
$type_label = $definition->get('label');
}
return $this->t('Are you sure you want to delete the %type config %item?', ['%type' => $type_label, '%item' => $this->name]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('config_update_ui.report');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('This action cannot be undone. Manually deleting configuration from this page can cause problems on your site due to missing dependencies, and should only be done if there is no other way to delete a problematic piece of configuration.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) {
$this->type = $config_type;
$this->name = $config_name;
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$value = $this->configRevert->getFromActive($this->type, $this->name);
if (!$value) {
$form_state->setErrorByName('', $this->t('There is no configuration @type named @name to delete', ['@type' => $this->type, '@name' => $this->name]));
return;
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configRevert->delete($this->type, $this->name);
drupal_set_message($this->t('The configuration was deleted.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
@@ -0,0 +1,143 @@
<?php
namespace Drupal\config_update_ui\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\config_update\ConfigListInterface;
use Drupal\config_update\ConfigRevertInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a confirmation form for reverting configuration.
*/
class ConfigRevertConfirmForm extends ConfirmFormBase {
/**
* The type of config being reverted.
*
* @var string
*/
protected $type;
/**
* The name of the config item being reverted, without the prefix.
*
* @var string
*/
protected $name;
/**
* The config lister.
*
* @var \Drupal\config_update\ConfigListInterface
*/
protected $configList;
/**
* The config reverter.
*
* @var \Drupal\config_update\ConfigRevertInterface
*/
protected $configRevert;
/**
* Constructs a ConfigRevertConfirmForm object.
*
* @param \Drupal\config_update\ConfigListInterface $config_list
* The config lister.
* @param \Drupal\config_update\ConfigRevertInterface $config_update
* The config reverter.
*/
public function __construct(ConfigListInterface $config_list, ConfigRevertInterface $config_update) {
$this->configList = $config_list;
$this->configRevert = $config_update;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config_update.config_list'),
$container->get('config_update.config_update')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'config_update_confirm';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
if ($this->type == 'system.simple') {
$type_label = $this->t('Simple configuration');
}
else {
$definition = $this->configList->getType($this->type);
$type_label = $definition->get('label');
}
return $this->t('Are you sure you want to revert the %type config %item to its source configuration?', ['%type' => $type_label, '%item' => $this->name]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('config_update_ui.report');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Customizations will be lost. This action cannot be undone.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Revert');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $config_type = NULL, $config_name = NULL) {
$this->type = $config_type;
$this->name = $config_name;
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$value = $this->configRevert->getFromExtension($this->type, $this->name);
if (!$value) {
$form_state->setErrorByName('', $this->t('There is no configuration @type named @name to import', ['@type' => $this->type, '@name' => $this->name]));
return;
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configRevert->revert($this->type, $this->name);
drupal_set_message($this->t('The configuration was reverted to its source.'));
$form_state->setRedirectUrl($this->getCancelUrl());
}
}
@@ -0,0 +1,283 @@
<?php
namespace Drupal\config_update_ui\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Verify the config revert report and its links.
*
* @group config
*/
class ConfigUpdateTest extends WebTestBase {
/**
* Modules to enable.
*
* Use the Search module because it has two included config items in its
* config/install, assuming node and user are also enabled.
*
* @var array.
*/
public static $modules = ['config', 'config_update', 'config_update_ui', 'search', 'node', 'user', 'block', 'text', 'field', 'filter'];
/**
* The admin user that will be created.
*/
protected $adminUser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create user and log in.
$this->adminUser = $this->drupalCreateUser(['access administration pages', 'administer search', 'view config updates report', 'synchronize configuration', 'export configuration', 'import configuration', 'revert configuration', 'delete configuration']);
$this->drupalLogin($this->adminUser);
// Make sure local tasks and page title are showing.
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
}
/**
* Tests the config report and its linked pages.
*/
public function testConfigReport() {
// Test links to report page.
$this->drupalGet('admin/config/development/configuration');
$this->clickLink('Updates report');
$this->assertNoReport();
// Verify some empty reports.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], [], []);
// Module, theme, and profile reports have no 'added' section.
$this->drupalGet('admin/config/development/configuration/report/module/search');
$this->assertReport('Search module', [], [], [], [], ['added']);
$this->drupalGet('admin/config/development/configuration/report/theme/classy');
$this->assertReport('Classy theme', [], [], [], [], ['added']);
$inactive = ['locale.settings' => 'Simple configuration'];
$this->drupalGet('admin/config/development/configuration/report/profile');
$this->assertReport('Testing profile', [], [], [], $inactive, ['added']);
// Delete the user search page from the search UI and verify report for
// both the search page config type and user module.
$this->drupalGet('admin/config/search/pages');
$this->clickLink('Delete');
$this->drupalPostForm(NULL, [], 'Delete');
$inactive = ['search.page.user_search' => 'Users'];
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], [], $inactive);
$this->drupalGet('admin/config/development/configuration/report/module/user');
$this->assertReport('User module', [], [], [], $inactive, ['added', 'changed']);
// Use the import link to get it back. Do this from the search page
// report to make sure we are importing the right config.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->clickLink('Import from source');
$this->assertText('The configuration was imported');
$this->assertNoReport();
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], [], []);
// Edit the node search page from the search UI and verify report.
$this->drupalGet('admin/config/search/pages');
$this->clickLink('Edit');
$this->drupalPostForm(NULL, [
'label' => 'New label',
'path' => 'new_path',
], 'Save search page');
$changed = ['search.page.node_search' => 'New label'];
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], $changed, []);
// Test the show differences link.
$this->clickLink('Show differences');
$this->assertText('Content');
$this->assertText('New label');
$this->assertText('node');
$this->assertText('new_path');
// Test the Back link.
$this->clickLink("Back to 'Updates report' page.");
$this->assertNoReport();
// Test the export link.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->clickLink('Export');
$this->assertText('Here is your configuration:');
$this->assertText('id: node_search');
$this->assertText('New label');
$this->assertText('path: new_path');
$this->assertText('search.page.node_search.yml');
// Test reverting.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->clickLink('Revert to source');
$this->assertText('Are you sure you want to revert');
$this->assertText('Search page');
$this->assertText('node_search');
$this->assertText('Customizations will be lost. This action cannot be undone');
$this->drupalPostForm(NULL, [], 'Revert');
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], [], []);
// Add a new search page from the search UI and verify report.
$this->drupalPostForm('admin/config/search/pages', [
'search_type' => 'node_search',
], 'Add new page');
$this->drupalPostForm(NULL, [
'label' => 'test',
'id' => 'test',
'path' => 'test',
], 'Add search page');
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$added = ['search.page.test' => 'test'];
$this->assertReport('Search page', [], $added, [], []);
// Test the export link.
$this->clickLink('Export');
$this->assertText('Here is your configuration:');
$this->assertText('id: test');
$this->assertText('label: test');
$this->assertText('path: test');
$this->assertText('search.page.test.yml');
// Test the delete link.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->clickLink('Delete');
$this->assertText('Are you sure');
$this->assertText('cannot be undone');
$this->drupalPostForm(NULL, [], 'Delete');
$this->assertText('The configuration was deleted');
// And verify the report again.
$this->drupalGet('admin/config/development/configuration/report/type/search_page');
$this->assertReport('Search page', [], [], [], []);
// Change the search module config and verify the actions work for
// simple config.
$this->drupalPostForm('admin/config/search/pages', [
'minimum_word_size' => 4,
], 'Save configuration');
$changed = ['search.settings' => 'search.settings'];
$this->drupalGet('admin/config/development/configuration/report/module/search');
$this->assertReport('Search module', [], [], $changed, [], ['added']);
$this->clickLink('Show differences');
$this->assertText('Config difference for Simple configuration search.settings');
$this->assertText('index::minimum_word_size');
$this->assertText('4');
$this->drupalGet('admin/config/development/configuration/report/module/search');
$this->clickLink('Export');
$this->assertText('minimum_word_size: 4');
$this->drupalGet('admin/config/development/configuration/report/module/search');
$this->clickLink('Revert to source');
$this->drupalPostForm(NULL, [], 'Revert');
$this->drupalGet('admin/config/development/configuration/report/module/search');
$this->assertReport('Search module', [], [], [], [], ['added']);
}
/**
* Asserts that the report page has the correct content.
*
* Assumes you are already on the report page.
*
* @param string $title
* Report title to check for.
* @param string[] $missing
* Array of items that should be listed as missing, name => label.
* @param string[] $added
* Array of items that should be listed as missing, name => label.
* @param string[] $changed
* Array of items that should be listed as changed, name => label.
* @param string[] $inactive
* Array of items that should be listed as inactive, name => label.
* @param string[] $skip
* Array of report sections to skip checking.
*/
protected function assertReport($title, $missing, $added, $changed, $inactive, $skip = []) {
$this->assertText('Configuration updates report for ' . $title);
$this->assertText('Generate new report');
if (!in_array('missing', $skip)) {
$this->assertText('Missing configuration items');
if (count($missing)) {
foreach ($missing as $name => $label) {
$this->assertText($name);
$this->assertText($label);
}
$this->assertNoText('None: all provided configuration items are in your active configuration.');
}
else {
$this->assertText('None: all provided configuration items are in your active configuration.');
}
}
if (!in_array('inactive', $skip)) {
$this->assertText('Inactive optional items');
if (count($inactive)) {
foreach ($inactive as $name => $label) {
$this->assertText($name);
$this->assertText($label);
}
$this->assertNoText('None: all optional configuration items are in your active configuration.');
}
else {
$this->assertText('None: all optional configuration items are in your active configuration.');
}
}
if (!in_array('added', $skip)) {
$this->assertText('Added configuration items');
if (count($added)) {
foreach ($added as $name => $label) {
$this->assertText($name);
$this->assertText($label);
}
$this->assertNoText('None: all active configuration items of this type were provided by modules, themes, or install profile.');
}
else {
$this->assertText('None: all active configuration items of this type were provided by modules, themes, or install profile.');
}
}
if (!in_array('changed', $skip)) {
$this->assertText('Changed configuration items');
if (count($changed)) {
foreach ($changed as $name => $label) {
$this->assertText($name);
$this->assertText($label);
}
$this->assertNoText('None: no active configuration items differ from their current provided versions.');
}
else {
$this->assertText('None: no active configuration items differ from their current provided versions.');
}
}
}
/**
* Asserts that the report is not shown.
*
* Assumes you are already on the report form page.
*/
protected function assertNoReport() {
$this->assertText('Report type');
$this->assertText('Configuration type');
$this->assertText('Module');
$this->assertText('Theme');
$this->assertText('Installation profile');
$this->assertText('Updates report');
$this->assertNoText('Missing configuration items');
$this->assertNoText('Added configuration items');
$this->assertNoText('Changed configuration items');
$this->assertNoText('Unchanged configuration items');
}
}
@@ -0,0 +1,37 @@
<?php
namespace Drupal\config_update;
/**
* Defines an interface for deleting config items.
*/
interface ConfigDeleteInterface {
/**
* Name of the event triggered on configuration delete.
*
* @see \Drupal\config_update\ConfigRevertEvent
* @see \Drupal\config_update\ConfigDeleteInterface::delete()
*/
const DELETE = 'config_update.delete';
/**
* Deletes a configuration item.
*
* This action triggers a ConfigDeleteInterface::DELETE event.
*
* @param string $type
* The type of configuration.
* @param string $name
* The name of the config item, without the prefix.
*
* @return bool
* TRUE if the operation succeeded; FALSE if the base configuration could
* not be found to delete. May also throw exceptions if there is a
* problem during deleting the configuration.
*
* @see \Drupal\config_update\ConfigDeleteInterface::DELETE
*/
public function delete($type, $name);
}
@@ -0,0 +1,46 @@
<?php
namespace Drupal\config_update;
/**
* Defines an interface for config differences.
*/
interface ConfigDiffInterface {
/**
* Decides if two configuration arrays are considered to be the same.
*
* The two arrays are considered to be the same if, after "normalizing", they
* have the same keys and values. It is up to the particular implementing
* class to decide what normalizing means.
*
* @param array $source
* Source config.
* @param array $target
* Target config.
*
* @return bool
* TRUE if the source and target are the same, and FALSE if they are
* different.
*/
public function same($source, $target);
/**
* Calculates differences between config.
*
* The two arrays are "normalized" and split into lines to compare
* differences. It is up to the particular implementing class to decide what
* normalizing means.
*
* @param array $source
* Source config.
* @param array $target
* Target config.
*
* @return \Drupal\Component\Diff\Diff
* Diff object for displaying line-by-line differences between source and
* target config.
*/
public function diff($source, $target);
}
@@ -0,0 +1,180 @@
<?php
namespace Drupal\config_update;
use Drupal\Component\Diff\Diff;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
/**
* Provides methods related to config differences.
*/
class ConfigDiffer implements ConfigDiffInterface {
use StringTranslationTrait;
/**
* List of elements to ignore when comparing config.
*
* @var string[]
*
* @see ConfigDiffer::format().
*/
protected $ignore;
/**
* Prefix to use to indicate config hierarchy.
*
* @var string
*
* @see ConfigDiffer::format().
*/
protected $hierarchyPrefix;
/**
* Prefix to use to indicate config values.
*
* @var string
*
* @see ConfigDiffer::format().
*/
protected $valuePrefix;
/**
* Constructs a ConfigDiffer.
*
* @param TranslationInterface $translation
* String translation service.
* @param string[] $ignore
* Config components to ignore.
* @param string $hierarchy_prefix
* Prefix to use in diffs for array hierarchy.
* @param string $value_prefix
* Prefix to use in diffs for array value.
*/
public function __construct(TranslationInterface $translation, $ignore = ['uuid', '_core'], $hierarchy_prefix = '::', $value_prefix = ' : ') {
$this->stringTranslation = $translation;
$this->hierarchyPrefix = $hierarchy_prefix;
$this->valuePrefix = $value_prefix;
$this->ignore = $ignore;
}
/**
* Normalizes config for comparison.
*
* Recursively removes elements in the ignore list from configuration,
* as well as empty array values, and sorts at each level by array key, so
* that config from different storage can be compared meaningfully.
*
* @param array $config
* Configuration array to normalize.
*
* @return array
* Normalized configuration array.
*
* @see ConfigDiffer::format()
* @see ConfigDiffer::$ignore
*/
protected function normalize($config) {
// Remove "ignore" elements.
foreach ($this->ignore as $element) {
unset($config[$element]);
}
// Recursively normalize remaining elements, if they are arrays.
foreach ($config as $key => $value) {
if (is_array($value)) {
$new = $this->normalize($value);
if (count($new)) {
$config[$key] = $new;
}
else {
unset($config[$key]);
}
}
}
// Sort and return.
ksort($config);
return $config;
}
/**
* {@inheritdoc}
*/
public function same($source, $target) {
$source = $this->normalize($source);
$target = $this->normalize($target);
return $source == $target;
}
/**
* Formats config for showing differences.
*
* To compute differences, we need to separate the config into lines and use
* line-by-line differencer. The obvious way to split into lines is:
* @code
* explode("\n", Yaml::encode($config))
* @endcode
* But this would highlight meaningless differences due to the often different
* order of config files, and also loses the indentation and context of the
* config hierarchy when differences are computed, making the difference
* difficult to interpret.
*
* So, what we do instead is to take the YAML hierarchy and format it so that
* the hierarchy is shown on each line. So, if you're in element
* $config['foo']['bar'] and the value is 'value', you will see
* 'foo::bar : value'.
*
* @param array $config
* Config array to format. Normalize it first if you want to do diffs.
* @param string $prefix
* (optional) When called recursively, the prefix to put on each line. Omit
* when initially calling this function.
*
* @return string[] Array of config lines formatted so that a line-by-line
* diff will show the context in each line, and meaningful differences will
* be computed.
*
* @see ConfigDiffer::normalize()
* @see ConfigDiffer::$hierarchyPrefix
* @see ConfigDiffer::$valuePrefix
*/
protected function format($config, $prefix = '') {
$lines = [];
foreach ($config as $key => $value) {
$section_prefix = ($prefix) ? $prefix . $this->hierarchyPrefix . $key : $key;
if (is_array($value)) {
$lines[] = $section_prefix;
$newlines = $this->format($value, $section_prefix);
foreach ($newlines as $line) {
$lines[] = $line;
}
}
elseif (is_null($value)) {
$lines[] = $section_prefix . $this->valuePrefix . $this->t('(NULL)');
}
else {
$lines[] = $section_prefix . $this->valuePrefix . $value;
}
}
return $lines;
}
/**
* {@inheritdoc}
*/
public function diff($source, $target) {
$source = $this->normalize($source);
$target = $this->normalize($target);
$source_lines = $this->format($source);
$target_lines = $this->format($target);
return new Diff($source_lines, $target_lines);
}
}
@@ -0,0 +1,74 @@
<?php
namespace Drupal\config_update;
/**
* Defines an interface for config listings.
*/
interface ConfigListInterface {
/**
* Lists the types of configuration available on the system.
*
* @return \Drupal\Core\Entity\EntityTypeInterface[]
* Array of entity type definitions, keyed by machine name of the type.
*/
public function listTypes();
/**
* Returns the entity type object for a given config type name.
*
* @param string $name
* Config entity type machine name.
*
* @return \Drupal\Core\Entity\EntityTypeInterface
* Entity type object with machine name $name.
*/
public function getType($name);
/**
* Returns the entity type object for a given config prefix.
*
* @param string $prefix
* Config prefix.
*
* @return \Drupal\Core\Entity\EntityTypeInterface
* Entity type object corresponding to $prefix.
*/
public function getTypeByPrefix($prefix);
/**
* Returns the entity type object for a given config object.
*
* @param string $name
* Name of the config object.
*
* @return string
* Name of the entity type that this is an instance of, determined by
* prefix. NULL for simple configuration.
*/
public function getTypeNameByConfigName($name);
/**
* Lists the config objects in active and extension storage.
*
* @param string $list_type
* Type of list to make: 'type', 'module', 'theme', or 'profile'.
* @param string $name
* Machine name of a configuration type, module, or theme to generate the
* list for. Ignored for profile, since that uses the active profile. Use
* type 'system.simple' for simple config, and 'system.all' to list all
* config items.
*
* @return array
* Array whose first element is the list of config objects in active
* storage, second is the list of config objects in extension storage,
* and third is the list of optional config objects in extension storage
* (the ones with dependencies from config/optional directories).
* Note that for everything except 'type' lists, the active storage list
* includes all configuration items in the system, not limited to ones from
* this module, theme, or profile.
*/
public function listConfig($list_type, $name);
}
@@ -0,0 +1,221 @@
<?php
namespace Drupal\config_update;
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Extension\Extension;
/**
* Provides methods related to config listing.
*/
class ConfigLister implements ConfigListInterface {
/**
* List of current config entity types, keyed by prefix.
*
* This is not set up until ConfigLister::listTypes() has been called.
*
* @var string[]
*/
protected $typesByPrefix = [];
/**
* List of current config entity type definitions, keyed by entity type.
*
* This is not set up until ConfigLister::listTypes() has been called.
*
* @var \Drupal\Core\Entity\EntityTypeInterface[]
*/
protected $definitions = [];
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The active config storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $activeConfigStorage;
/**
* The extension config storage.
*
* @var \Drupal\Core\Config\ExtensionInstallStorage
*/
protected $extensionConfigStorage;
/**
* The extension config storage for optional config.
*
* @var \Drupal\Core\Config\ExtensionInstallStorage
*/
protected $extensionOptionalConfigStorage;
/**
* Constructs a ConfigLister.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\StorageInterface $active_config_storage
* The active config storage.
* @param \Drupal\Core\Config\ExtensionInstallStorage $extension_config_storage
* The extension config storage.
* @param \Drupal\Core\Config\ExtensionInstallStorage $extension_optional_config_storage
* The extension config storage for optional config items.
*/
public function __construct(EntityTypeManagerInterface $entity_manager, StorageInterface $active_config_storage, ExtensionInstallStorage $extension_config_storage, ExtensionInstallStorage $extension_optional_config_storage) {
$this->entityManager = $entity_manager;
$this->activeConfigStorage = $active_config_storage;
$this->extensionConfigStorage = $extension_config_storage;
$this->extensionOptionalConfigStorage = $extension_optional_config_storage;
}
/**
* Sets up and returns the entity definitions list.
*/
public function listTypes() {
if (count($this->definitions)) {
return $this->definitions;
}
foreach ($this->entityManager->getDefinitions() as $entity_type => $definition) {
if ($definition->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
$this->definitions[$entity_type] = $definition;
$prefix = $definition->getConfigPrefix();
$this->typesByPrefix[$prefix] = $entity_type;
}
}
ksort($this->definitions);
return $this->definitions;
}
/**
* {@inheritdoc}
*/
public function getType($name) {
$definitions = $this->listTypes();
return isset($definitions[$name]) ? $definitions[$name] : NULL;
}
/**
* {@inheritdoc}
*/
public function getTypeByPrefix($prefix) {
$definitions = $this->listTypes();
return isset($this->typesByPrefix[$prefix]) ? $definitions[$this->typesByPrefix[$prefix]] : NULL;
}
/**
* {@inheritdoc}
*/
public function getTypeNameByConfigName($name) {
$definitions = $this->listTypes();
foreach ($this->typesByPrefix as $prefix => $entity_type) {
if (strpos($name, $prefix) === 0) {
return $entity_type;
}
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function listConfig($list_type, $name) {
$active_list = [];
$install_list = [];
$optional_list = [];
$definitions = $this->listTypes();
switch ($list_type) {
case 'type':
if ($name == 'system.all') {
$active_list = $this->activeConfigStorage->listAll();
$install_list = $this->extensionConfigStorage->listAll();
$optional_list = $this->extensionOptionalConfigStorage->listAll();
}
elseif ($name == 'system.simple') {
// Listing is done by prefixes, and simple config doesn't have one.
// So list all and filter out all known prefixes.
$active_list = $this->omitKnownPrefixes($this->activeConfigStorage->listAll());
$install_list = $this->omitKnownPrefixes($this->extensionConfigStorage->listAll());
$optional_list = $this->omitKnownPrefixes($this->extensionOptionalConfigStorage->listAll());
}
elseif (isset($this->definitions[$name])) {
$definition = $this->definitions[$name];
$prefix = $definition->getConfigPrefix();
$active_list = $this->activeConfigStorage->listAll($prefix);
$install_list = $this->extensionConfigStorage->listAll($prefix);
$optional_list = $this->extensionOptionalConfigStorage->listAll($prefix);
}
break;
case 'profile':
$name = Settings::get('install_profile');
// Intentional fall-through here to the 'module' or 'theme' case.
case 'module':
case 'theme':
$active_list = $this->activeConfigStorage->listAll();
$install_list = $this->listProvidedItems($list_type, $name);
$optional_list = $this->listProvidedItems($list_type, $name, TRUE);
break;
}
return [$active_list, $install_list, $optional_list];
}
/**
* Returns a list of the install storage items for an extension.
*
* @param string $type
* Type of extension ('module', etc.).
* @param string $name
* Machine name of extension.
* @param bool $do_optional
* FALSE (default) to list config/install items, TRUE to list
* config/optional items.
*
* @return string[]
* List of config items provided by this extension.
*/
protected function listProvidedItems($type, $name, $do_optional = FALSE) {
$pathname = drupal_get_filename($type, $name);
$component = new Extension(\Drupal::root(), $type, $pathname);
if ($do_optional) {
$names = $this->extensionOptionalConfigStorage->getComponentNames([$component]);
}
else {
$names = $this->extensionConfigStorage->getComponentNames([$component]);
}
return array_keys($names);
}
/**
* Omits config with known prefixes from a list of config names.
*/
protected function omitKnownPrefixes($list) {
$prefixes = array_keys($this->typesByPrefix);
$list = array_combine($list, $list);
foreach ($list as $name) {
foreach ($prefixes as $prefix) {
if (strpos($name, $prefix) === 0) {
unset($list[$name]);
}
}
}
return array_values($list);
}
}
@@ -0,0 +1,66 @@
<?php
namespace Drupal\config_update;
use Symfony\Component\EventDispatcher\Event;
/**
* Event context class for configuration revert/import events.
*
* This class is passed in as the event when the
* \Drupal\config_update\ConfigRevertInterface::IMPORT,
* \Drupal\config_update\ConfigDeleteInterface::DELETE, and
* \Drupal\config_update\ConfigRevertInterface::REVERT events are triggered.
*/
class ConfigRevertEvent extends Event {
/**
* The type of configuration that is being imported or reverted.
*
* @var string
*/
protected $type;
/**
* The name of the config item being imported or reverted, without prefix.
*
* @var string
*/
protected $name;
/**
* Constructs a new ConfigRevertEvent.
*
* @param string $type
* The type of configuration being imported or reverted.
* @param string $name
* The name of the config item being imported/reverted, without prefix.
*/
public function __construct($type, $name) {
$this->type = $type;
$this->name = $name;
}
/**
* Returns the type of configuration being imported or reverted.
*
* @return string
* The type of configuration, either 'system.simple' or a config entity
* type machine name.
*/
public function getType() {
return $this->type;
}
/**
* Returns the name of the config item, without prefix.
*
* @return string
* The name of the config item being imported/reverted/deleted, with the
* prefix.
*/
public function getName() {
return $this->name;
}
}
@@ -0,0 +1,96 @@
<?php
namespace Drupal\config_update;
/**
* Defines an interface for config import and revert operations.
*/
interface ConfigRevertInterface {
/**
* Name of the event triggered on configuration import.
*
* @see \Drupal\config_update\ConfigRevertEvent
* @see \Drupal\config_update\ConfigRevertInterface::import()
*/
const IMPORT = 'config_update.import';
/**
* Name of the event triggered on configuration revert.
*
* @see \Drupal\config_update\ConfigRevertEvent
* @see \Drupal\config_update\ConfigRevertInterface::revert()
*/
const REVERT = 'config_update.revert';
/**
* Imports configuration from extension storage to active storage.
*
* This action triggers a ConfigRevertInterface::IMPORT event if the
* configuration could be imported.
*
* @param string $type
* The type of configuration.
* @param string $name
* The name of the config item, without the prefix.
*
* @return bool
* TRUE if the operation succeeded; FALSE if the configuration could not
* be found to import. May also throw exceptions if there is a problem
* during saving the configuration.
*
* @see \Drupal\config_update\ConfigRevertInterface::IMPORT
*/
public function import($type, $name);
/**
* Reverts configuration to the value from extension storage.
*
* This action triggers a ConfigRevertInterface::REVERT event.
*
* @param string $type
* The type of configuration.
* @param string $name
* The name of the config item, without the prefix.
*
* @return bool
* TRUE if the operation succeeded; FALSE if the base configuration could
* not be found to revert to. May also throw exceptions if there is a
* problem during saving the configuration.
*
* @see \Drupal\config_update\ConfigRevertInterface::REVERT
*/
public function revert($type, $name);
/**
* Gets the current active value of configuration.
*
* @param string $type
* The type of configuration. Or pass '' to indicate that $name is the full
* name.
* @param string $name
* The name of the config item, without the prefix.
*
* @return array
* The configuration value.
*/
public function getFromActive($type, $name);
/**
* Gets the extension storage value of configuration.
*
* This is the value from a file in the config/install or config/optional
* directory of a module, theme, or install profile.
*
* @param string $type
* The type of configuration. Or pass '' to indicate that $name is the full
* name.
* @param string $name
* The name of the config item, without the prefix.
*
* @return array|false
* The configuration value, or FALSE if it could not be located.
*/
public function getFromExtension($type, $name);
}
@@ -0,0 +1,218 @@
<?php
namespace Drupal\config_update;
use Drupal\Core\Config\StorageInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Provides methods related to config reverting, deleting, and importing.
*
* In this class, when any import or revert operation is requested, the
* configuration that is being reverted or imported is searched for in both the
* config/install repository and config/optional. This happens automatically.
*/
class ConfigReverter implements ConfigRevertInterface, ConfigDeleteInterface {
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* The active config storage.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $activeConfigStorage;
/**
* The extension config storage for config/install config items.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $extensionConfigStorage;
/**
* The extension config storage for config/optional config items.
*
* @var \Drupal\Core\Config\ExtensionInstallStorage
*/
protected $extensionOptionalConfigStorage;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* Constructs a ConfigReverter.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Config\StorageInterface $active_config_storage
* The active config storage.
* @param \Drupal\Core\Config\StorageInterface $extension_config_storage
* The extension config storage.
* @param \Drupal\Core\Config\StorageInterface $extension_optional_config_storage
* The extension config storage for optional config items.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
*/
public function __construct(EntityTypeManagerInterface $entity_manager, StorageInterface $active_config_storage, StorageInterface $extension_config_storage, StorageInterface $extension_optional_config_storage, ConfigFactoryInterface $config_factory, EventDispatcherInterface $dispatcher) {
$this->entityManager = $entity_manager;
$this->activeConfigStorage = $active_config_storage;
$this->extensionConfigStorage = $extension_config_storage;
$this->extensionOptionalConfigStorage = $extension_optional_config_storage;
$this->configFactory = $config_factory;
$this->dispatcher = $dispatcher;
}
/**
* {@inheritdoc}
*/
public function import($type, $name) {
// Read the config from the file.
$full_name = $this->getFullName($type, $name);
$value = $this->extensionConfigStorage->read($full_name);
if (!$value) {
$value = $this->extensionOptionalConfigStorage->read($full_name);
}
if (!$value) {
return FALSE;
}
// Save it as a new config entity or simple config.
if ($type == 'system.simple') {
$this->configFactory->getEditable($full_name)->setData($value)->save();
}
else {
$entity_storage = $this->entityManager->getStorage($type);
$entity = $entity_storage->createFromStorageRecord($value);
$entity->save();
}
// Trigger an event notifying of this change.
$event = new ConfigRevertEvent($type, $name);
$this->dispatcher->dispatch(ConfigRevertInterface::IMPORT, $event);
return TRUE;
}
/**
* {@inheritdoc}
*/
public function revert($type, $name) {
// Read the config from the file.
$full_name = $this->getFullName($type, $name);
$value = $this->extensionConfigStorage->read($full_name);
if (!$value) {
$value = $this->extensionOptionalConfigStorage->read($full_name);
}
if (!$value) {
return FALSE;
}
if ($type == 'system.simple') {
// Load the current config and replace the value.
$this->configFactory->getEditable($full_name)->setData($value)->save();
}
else {
// Load the current config entity and replace the value, with the
// old UUID.
$definition = $this->entityManager->getDefinition($type);
$id_key = $definition->getKey('id');
$id = $value[$id_key];
$entity_storage = $this->entityManager->getStorage($type);
$entity = $entity_storage->load($id);
$uuid = $entity->get('uuid');
$entity = $entity_storage->updateFromStorageRecord($entity, $value);
$entity->set('uuid', $uuid);
$entity->save();
}
// Trigger an event notifying of this change.
$event = new ConfigRevertEvent($type, $name);
$this->dispatcher->dispatch(ConfigRevertInterface::REVERT, $event);
return TRUE;
}
/**
* {@inheritdoc}
*/
public function delete($type, $name) {
$full_name = $this->getFullName($type, $name);
if (!$full_name) {
return FALSE;
}
$config = $this->configFactory->getEditable($full_name);
if (!$config) {
return FALSE;
}
$config->delete();
// Trigger an event notifying of this change.
$event = new ConfigRevertEvent($type, $name);
$this->dispatcher->dispatch(ConfigDeleteInterface::DELETE, $event);
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getFromActive($type, $name) {
$full_name = $this->getFullName($type, $name);
return $this->activeConfigStorage->read($full_name);
}
/**
* {@inheritdoc}
*/
public function getFromExtension($type, $name) {
$full_name = $this->getFullName($type, $name);
$value = $this->extensionConfigStorage->read($full_name);
if (!$value) {
$value = $this->extensionOptionalConfigStorage->read($full_name);
}
return $value;
}
/**
* Returns the full name of a config item.
*
* @param string $type
* The config type, or '' to indicate $name is already prefixed.
* @param string $name
* The config name, without prefix.
*
* @return string
* The config item's full name.
*/
protected function getFullName($type, $name) {
if ($type == 'system.simple' || !$type) {
return $name;
}
$definition = $this->entityManager->getDefinition($type);
$prefix = $definition->getConfigPrefix() . '.';
return $prefix . $name;
}
}