Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Status: Active » Needs review
FileSize
342 bytes

Just to see what happens.

Probably nothing (passing tests), due to dependencies of dependencies.

Status: Needs review » Needs work

The last submitted patch, 1: drupal8.required-field.1.patch, failed testing.

sun’s picture

Interesting. User depends on Field.

andypost’s picture

@sun user picture is a field, so probably image also needed

sun’s picture

Status: Needs review » Needs work

The dependency graph in #1688162-10: Replace required flag of modules with proper dependencies explains why the patch passed after making User module depend on Field module → User module is required, so Field module is always installed.

I wonder whether it is possible to make the dependency on the 'field.info' service optional?

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "field.info" does not exist.

Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition('field.info')
Symfony\Component\DependencyInjection\ContainerBuilder->get('field.info', 1)
Drupal\Core\DependencyInjection\ContainerBuilder->get('field.info')
Drupal\user\UserStorageController::createInstance(Object, Object)
Drupal\Core\Entity\EntityManager->getController('user', 'storage', 'getStorageClass')
Drupal\Core\Entity\EntityManager->getStorageController('user')
entity_load('user', 1, )
user_load(1)
install_configure_form_submit(Array, Array)
call_user_func_array('install_configure_form_submit', Array)
Drupal\Core\Form\FormBuilder->executeHandlers('submit', Array, Array)
Drupal\Core\Form\FormBuilder->processForm('install_configure_form', Array, Array)
Drupal\Core\Form\FormBuilder->submitForm('install_configure_form', Array)
drupal_form_submit('install_configure_form', Array)
install_run_task(Array, Array)
install_run_tasks(Array)
install_drupal(Array)
Drupal\simpletest\WebTestBase->setUp()
Drupal\user\Tests\UserAccountLinksTests->setUp()
Drupal\simpletest\TestBase->run()
simpletest_script_run_one_test('726', 'Drupal\user\Tests\UserAccountLinksTests')
andypost’s picture

FieldInfo is needed for FieldableDatabaseStorageController and only for fieldInfo->getBundleInstances()
So at least any fieldable entity require it to properly populate fields, probably related #2114707: Allow per-bundle overrides of field definitions

yched’s picture

The goal is to replace field.module's FieldInfo with a registry of base + configurable fields handled by Core/Field in #2116363: Unified repository of field definitions (cache + API).

sun’s picture

Hm, yeah, while it would be simple to make the injected FieldInfo service optional, the actual crux is this already:

class UserStorageController extends FieldableDatabaseStorageController {

  public function __construct(...) {
    parent::__construct($entity_type, $database, $field_info, $uuid_service);

So unless we're able to make FieldInfo also optional for FieldableDatabaseStorageController, I can only guess this means that this issue must be postponed on #2114707: Allow per-bundle overrides of field definitions and #2116363: Unified repository of field definitions (cache + API) — and after those, this issue might be obsolete, but let's see...

sun’s picture

Status: Postponed » Needs review
FileSize
36.16 KB

I found a solution :-)

Installer says: "Installing 4 of 4 modules." :)

The trick was to supply a Drupal\Core\Field\FieldInfoNull implementation that just returns no field info for all methods + register that in core.services.yml, so that it is used, unless Field module is installed.

Unfortunately, some calls to procedural field module functions appear to be scattered across core, so even though I'm able to successfully finish the installation, visiting the front page (/user/1) blows up, just because:

Fatal error: Call to undefined function Drupal\entity\field_info_extra_fields()
in core\modules\entity\lib\Drupal\entity\EntityDisplayBase.php on line 207

:-/

Status: Needs review » Needs work

The last submitted patch, 9: field.required.9.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
40.63 KB
4.46 KB

Oh hey, some more quick adjustments + I'm able to view /user/1 and /user/1/edit works, too :-)

Status: Needs review » Needs work

The last submitted patch, 11: field.required.10.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
40.92 KB
1.87 KB

Fixed FieldInfo is incompatible with FieldInfoInterface.

→ I had to remove the type-hints for some Field module classes, because Drupal\Core\Field\FieldInfoInterface can obviously not type hint those. ;)

Obviously, I just want to see how far we can get with this approach... so please don't take this too seriously :)

Status: Needs review » Needs work

The last submitted patch, 13: field.required.13.patch, failed testing.

Berdir’s picture

This will be a lot easier after #2167167: Remove field_info_*() ;)

Berdir’s picture

Status: Needs work » Needs review
FileSize
342 bytes

Let's see what happens. A lot of field type modules like text already depend on field, so most dependencies should already be covered...

Status: Needs review » Needs work

The last submitted patch, 16: field-is-no-more-required-2199637-16.patch, failed testing.

Berdir’s picture

Stupid DependencyTest is stupid! ;)

Status: Needs work » Needs review
sun’s picture

Yes, field modules are specifying a dependency on Field module already. However, what about the opposite direction?

Doesn't User module still depend on Field module?

(User module is installed separately as the second module right after System module by the installer.)

In essence, the question is whether you can actually install Drupal without Field module. This can be tested by hitting the installer with install.php?langcode=en&profile=testing

Berdir’s picture

No, user does not depend on field because the field.info service is gone. The integration of configurable fields into entity storage is 99% optional, field.module hooks into the relevant processes.

There are still a handful of references/dependencies on field.module in Drupal\Core\Field|Entity, see #2079427: Core/Entity depends on classes / functions from field.module, but they're going away, nothing blocking left.

There is one exception and I hit that when I tried to move the user roles table to a normal field table that is managed by the entity storage, see #2248977: Complete support for multi-value base fields in ContentEntitySchemaHandler and use it for the user.roles field. But that's just a stupid static method call that is already fixed in @plach's entity storage issue, see the issue above.

Berdir’s picture

Testing by removing the required property + "drush si -y testing", works fine.

martin107’s picture

This makes perfect sense to me, but before RTBC lets see what testbot thinks there have been lots of commits.

today, locally I too can drush site install :)

Status: Needs review » Needs work

The last submitted patch, 16: field-is-no-more-required-2199637-16.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
13.01 KB

Interesting, now we actually had test fails :)

Fixed two problems:

- WidgetBase called functions from field.module for that filter xss stuff. Moved those to WidgetBase for now as public static, they're also used from some formatters and views. Not sure if there's a better place for this? a helper class maybe? With this change, the contact tests, which are now using widgets, are verifying that you can do this for base fields and core field types, without field.module.

- content_translation_install() is updating field_storage_config entities, added a module exists check there as it would theoretically be possible to use it without field.module.

Status: Needs review » Needs work

The last submitted patch, 26: optional-field-module-2199637-26.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
13.01 KB
748 bytes

Status: Needs review » Needs work

The last submitted patch, 28: optional-field-module-2199637-28.patch, failed testing.

Berdir’s picture

Status: Needs work » Needs review
FileSize
17.93 KB
4.92 KB

Forgot to update the calls to that method. Pretty sure that WidgeBase is not the right place now :)

Status: Needs review » Needs work

The last submitted patch, 30: optional-field-module-2199637-30.patch, failed testing.

yched’s picture

Ouch - yeah, not sure where to put field_filter_xss_*(), and WidgetBase is not the right place. A FieldXss utility class ? :-/

As a side note, I didn't closely follow the autoescape / SafeMarkup thing, but the resulting code in field_filter_xss() is a bit weird :
#1825952: Turn on twig autoescape by default did :

  function field_filter_xss($string) {
-    return Html::normalize(Xss::filter($string, _field_filter_xss_allowed_tags()));
+  return SafeMarkup::set(Html::normalize(Xss::filter($string, _field_filter_xss_allowed_tags())));
  }

but Xss::filter() already calls SafeMarkup::set(), so we call it twice ?

Backtracking through history:
- D7 just does return filter_xss($string, _field_filter_xss_allowed_tags()) there.
- #1798654: Clean faulty HTML in help description of field widgets wrapped that in _filter_htmlcorrector()
- #2195745: Replace _filter_htmlcorrector() with a utility class in core replaced _filter_htmlcorrector(filter_xss()) with Html::normalize(Xss::filter())
- #1825952: Turn on twig autoescape by default wrapped the above in SafeMarkup::set(), but also made Xss::filter() itself call SafeMarkup::set()...

Pinging the folks in #1825952: Turn on twig autoescape by default.

yched’s picture

From @chx :
"You are feeding a safe string to Html::normalize so the result will be safe too but the output is not necessarily the same as the input so the new string needs to be marked as safe too"

Then, maybe we could Html::normalize() *before* passing to Xss::filter() ?

Pinging the folks in #1798654: Clean faulty HTML in help description of field widgets.

Berdir’s picture

Status: Needs work » Needs review
FileSize
21.39 KB

Hm, what about making it a fancy trait? Has the limitation that only OO code can use it, but all calls in HEAD are already in classes.

Did not change anything about those calls, not sure how related it is for this issue, as I'm only moving it.

swentel’s picture

Status: Needs review » Needs work

Trait works for me. Mostly nitpicks left.

  1. --- /dev/null
    +++ b/core/lib/Drupal/Core/Field/AllowedTagsXssTrait.php
    

    Maybe this shouldn't live in Core/Field but somewhere more general, like in Component\Utility ?

  2. +++ b/core/lib/Drupal/Core/Field/AllowedTagsXssTrait.php
    @@ -0,0 +1,52 @@
    +   * Filters an HTML string to prevent cross-site-scripting (XSS) vulnerabilities.
    

    80 chars

  3. +++ b/core/lib/Drupal/Core/Field/AllowedTagsXssTrait.php
    @@ -0,0 +1,52 @@
    +   *   An XSS safe version of $string, or an empty string if $string is not valid
    

    same

  4. +++ b/core/lib/Drupal/Core/Field/AllowedTagsXssTrait.php
    @@ -0,0 +1,52 @@
    +} ¶
    

    redundant space

Berdir’s picture

Status: Needs work » Needs review
FileSize
21.41 KB
1.54 KB

Improved documentation. We agreed that we keep this trait in Core\Field for now.

swentel’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. I was confused first about the removal of the static on sanitizeLabel() but it would now work anymore otherwise.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

We need a change record because we're removing functions and introducing a trait.

swentel’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record

Change record at https://www.drupal.org/node/2337599
Tentatively setting to RTBC again.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Needs a reroll

git ac https://www.drupal.org/files/issues/optional-field-module-2199637-37.patch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 21921  100 21921    0     0   119k      0 --:--:-- --:--:-- --:--:--  139k
error: patch failed: core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php:7
error: core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php: patch does not apply
swentel’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs reroll
FileSize
21.42 KB
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5de9e40 and pushed to 8.0.x. Thanks!

diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 3f9e58c..ec8d2b7 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -4,9 +4,6 @@
  * Attach custom data fields to Drupal entities.
  */
 
-use Drupal\Component\Utility\Html;
-use Drupal\Component\Utility\SafeMarkup;
-use Drupal\Component\Utility\Xss;
 use Drupal\Core\Config\ConfigImporter;
 use Drupal\Core\Entity\EntityTypeInterface;
 use Drupal\Core\Extension\Extension;
diff --git a/core/modules/field/src/Plugin/views/argument/ListString.php b/core/modules/field/src/Plugin/views/argument/ListString.php
index b90baac..e78a9f7 100644
--- a/core/modules/field/src/Plugin/views/argument/ListString.php
+++ b/core/modules/field/src/Plugin/views/argument/ListString.php
@@ -10,7 +10,6 @@
 use Drupal\Component\Utility\String as UtilityString;
 use Drupal\Core\Field\AllowedTagsXssTrait;
 use Drupal\Core\Form\FormStateInterface;
-use Drupal\Core\Field\WidgetBase;
 use Drupal\views\ViewExecutable;
 use Drupal\views\Plugin\views\display\DisplayPluginBase;
 use Drupal\views\Plugin\views\argument\String;

Cleaned up the use statements on commit.

  • alexpott committed 5de9e40 on 8.0.x
    Issue #2199637 by Berdir, sun, swentel: Replace "required" flag of Field...

Status: Fixed » Closed (fixed)

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