Problem/Motivation

You can into a situation where the PHP module is uninstallable.

Steps to reproduce:

  1. Install the PHP module
  2. Go to admin/config/content/formats/manage/php_code and untick the php filter plugin checkbox
  3. Uninstall the PHP module
  4. Try to reinstall the PHP module
  5. For extra kicks disable the PHP filter format on admin/config/content/formats/manage and you can even see it :)

Another interesting scenario:

  1. Install the PHP module
  2. Go to admin/config/content/formats/manage and disable the PHP filter format
  3. Uninstall the PHP module
  4. Reinstall the PHP module - it works!

Filter formats have a special place in Drupal because of their relationship to security. This is why they can't be deleted. I think the only way forward is to move the filter to config/optional so that existing sites can take advantage of the PHP filter plugin even have they have a disabled PHP filter format. The second scenario is tricky though because the whole point is that you're not supposed to be able to delete filter formats.

Proposed resolution

Make dependencies correct in default config and move it to optional so that even if a site has a disabled format (or an enabled format) called filter.format.php_code the module can be installed.

Remaining tasks

Decide whether this approach is correct.

User interface changes

None

API changes

None

Data model changes

Original report

When I try to install the PHP module (on Drupal 8), I get this message:

Unable to install PHP Filter, filter.format.php_code already exists in active configuration.

Since PHP filter is currently not working on my site, I cannot understand where it is seeing this file. Please help.

Thanks,
John

CommentFileSizeAuthor
#16 2639336.16.patch757 bytesalexpott

Comments

jnimchuk created an issue. See original summary.

hass’s picture

Component: Miscellaneous » Code
Priority: Critical » Normal

What other modules are you running? Have you uninstalled the module and try to reinstall ?

jnimchuk’s picture

Yes, I uninstalled the module, deleted the files, and tried installing again.

I believe now that the issue has to do with upgrading from Drupal 6. Maybe something carried over related to PHP filter.

Thoughts?

jdn

hass’s picture

No idea. You need to debug for us...

jnimchuk’s picture

But where is your install looking for:

filter.format.php_code ???

jnimchuk’s picture

OK, FYI.

There were a couple of references hanging in the database (copied over from DR6). I deleted these records and Voila!

hass’s picture

Title: PHP module does not install » filter.format.php_code already exists in active configuration
Category: Support request » Bug report

Can you share a patch, so this does not happen again to other users. Maybe it is a core issue, but I have no idea how to reproduce.

quindio’s picture

I am playing with D6 to D8 migration and I added the php module and I am getting the errros
Unable to install PHP Filter, filter.format.php_code already exists in active configuration.

Can some one tell me how to fix the problem!!!

Thanks

quindio’s picture

my D6 migration brought PHP_FILTER and this does not allow me load the PHP module
I still get the error "Unable to install PHP Filter, filter.format.php_code already exists in active configuration."

I remove php_code reference from the DB table migrate_map_d6_filter_format and the
PHP_FILTER does not show in the nodes as a format choice but I am still not able to load the the PHP module.

Any advice???

Thanks,

ryrye’s picture

In reply to a couple of people above who had problems trying to fix this when upgrading D6 -> D8, here's what I did to fix it:

There were a couple of rows in the database with refs to php_code that I changed:

  • In migrate_map_d6_filter_format, changed the "php_code" value in the destid1 column to "php_code_old".
  • In config table, changed the "filter.format.php_code" value in the name column to "filter.format.php_code_old".

I'll probably delete these now that the module is successfully enabled.

quindio’s picture

#10 is correct. I was able to do the same things, these are the tables that
I found 'php_code':

  • block_content__body
  • block_content_revision__body
  • config
  • key_value
  • node__body
  • node_revision__body

After clearing these tables I installed and enabled the php module
everything looks good except that you will get the following in your logs:
"Missing filter plugin: filter_null."

I proceed to set the filter to php_code on a block but the page that uses that
block crashes then I disable the php module via the GUI('extends') and my
page is back.

After this you can not enable the php filter using the GUI because once disable
the filter disappears.

This is great if you are not using php filter in your site but if you need php you
still end up without a solution.

After all of these I am still not able to use the php filter

HELP!!!

quindio’s picture

ryrye, where you able to use PHP on your Drupal 8 site?

Maybe, I cleared to many tables. I Will try just clearing the
migrate_map_d6_filter_format and config

Someone told me that you can remove the all of the
migrate_?? tables

alexpott’s picture

This is because filter.format.php_code is missing a dependency on the php module - how was it generated?

alexpott’s picture

Hmmm but actually the install process will add the missing dependency still the default config should have it.

alexpott’s picture

Issue summary: View changes

So this is a fun issue! It is caused by the magic of filter formats and the fact they aren't deleteable through the UI. Added steps to reproduce to the issue summary.

alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new757 bytes

Here's a solution that will allow people to re-install and at least get the use of the filter again.

  • hass committed 806c2a9 on 8.x-1.x authored by alexpott
    Issue #2639336 by alexpott: filter.format.php_code already exists in...
hass’s picture

Status: Needs review » Fixed

Many thanks for your help.

Status: Fixed » Needs work

The last submitted patch, 16: 2639336.16.patch, failed testing.

hass’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

numerabilis’s picture

Could you teach me how to apply this patch? I don´t know how to apply PATCHes... I need to know how to do that! I migrated D6 to D8 and I am having this php filter issue, no content are showing, my site is full of links pointing to blank pages.

nelslynn’s picture

Was this patch applied to the dev version? I still get this error with both dev (2016-Apr-28) and 8.x-1.0-beta2 versions.

Unable to install PHP Filter, filter.format.php_code already exists in active configuration.
BartNijs’s picture

The patch wasn't applied to the beta version, but all you have to do is move one file in the module's folder:
from config/install/filter.format.php_code.yml to config/optional/filter.format.php_code.yml

kundu’s picture

#24 solved it. Thank you.

I wonder why it did it.

mxr10’s picture

this work for me:
move one file in the module's folder:
from config/install/filter.format.php_code.yml to config/optional/filter.format.php_code.yml
like @BartNijs said thank you

ecosty’s picture

I think the best option is to remove the current configuration first:

drush cdel filter.format.php_code
drush en php
mandymeng’s picture

#27 fixed my problem. Thank you @ecosty.

drush cdel filter.format.php_code
drush en php
drush cache-rebuild