Quantcast
Channel: Issues for Drupal core
Viewing all 294899 articles
Browse latest View live

Change the scaffolding documentation link in README.txt for Drupal 9


\Drupal\Core\Config\FileStorageFactory::getSync() should throw a more specific exception

$
0
0

Discovered in #2466197: Staging directory should not have to be writeable.

Problem/Motivation

\Drupal\Core\Config\FileStorageFactory::getSync() just throws a \Exception when the config directory type does not exist - that's way too generic.

Proposed resolution

Create a more specific exception.

Remaining tasks

  • Create new exception type
  • Review and commit

User interface changes

None

API changes

A new exception - but any code catching the existing exception will work because the new exception will extend from \Exception

Deprecate user_password and move to Utility component

Use the default PHP session ID instead of generating a custom one

$
0
0

Background

  1. The session id is a random value generated when a session is started. The session id is stored as a cookie in the browser such that on subsequent visits the data stored in the session can be loaded and reused. This issue is about the session id (cookie value) and not about the session name (cookie name).
  2. Drupal does not rely on built-in PHP methods for generating the session id currently, but uses a random 32 byte value.

  3. Before Drupal 7.24 different methods were used for anonymous vs. authenticated users, such that anonymous session ids were less expensive to generate.

    (see this commit; also note that the comment about "less random sessions" is wrong now).

  4. In contrast Symfony does not expect that the session-id is changed manually after the session has been started (see [...]\Session\Storage\Proxy\AbstractProxy::setId() and completely relies on the PHP built-in function session_regenerate_id() (see [...]\Session\Storage\NativeSessionStorage::regenerate().

Problem

  1. Our approach does not allow us to use session_regenerate_id().
  2. Instead, it is necessary to override NativeSessionStorage::regenerate completely and re-implement the mechanism in custom code (see #801278: Authenticated users getting "less random" session IDs).

Proposed solution

  1. PHP 5.4 ships with improvements regarding session ID generation:

    1. The INI setting session.entropy_file defaults to /dev/urandom or /dev/arandom if it is available (session.c (5.4) vs session.c (5.3)). On Windows, the Random API is used.
    2. On machines with /dev/urandom or /dev/arandom present on compile time session.entropy_length defaults to 32. On Windows, this seemingly has to be configured manually.
  2. According to the OWASP PHP Security Cheat Sheet:

    PHP's default session facilities are considered safe, the generated PHPSessionID is random enough, but the storage is not necessarily safe.

  3. When using the Drupal Crypt::randomBytes() function, the best (most secure and most performing) random source is selected automatically. The performance of both approaches was analyzed in #9. According to the results, no performance regression is to be expected when switching to PHP built-in session id generation.
  4. → Remove our custom code for generating session IDs and rely on the native PHP functionality instead.

API changes

Support scalar typehints in ProxyBuilder and as a result support PHP 8

$
0
0

Problem/Motivation

ProxyBuilder only has limited supported for built-in typehints like array and callable. It should support string, int etc... Also PHP 8 has deprecated \ReflectionParamter::getClass().

Proposed resolution

Fix it and add tests.

#3156542: \ReflectionParamter::getClass() is deprecated in PHP 8.0 handles other \ReflectionParamter::getClass() calls.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

ProxyBuilder now supports scalar typehints like string

Title variable isn't set by Syndicate block - so the link text is an unfinished sentence

$
0
0

Problem/Motivation

The node module provides a "syndicate" block, which contains a link to rss.xml.

The link text is an unfinished sentence: "Subscribe to".

The link is generated in SyndicateBlock.php using '#theme' => 'feed_icon'.

The corresponding feed-icon.html.twig template expects a top-level variable called title like so:

{{ 'Subscribe to @title'|t({'@title': title}) }}.

However no title variable has been passed in to the theme template by SyndicateBlock.php, so the link is an unfinished sentence. It's not clear what was originally intended for this to say. We could look back to how things worked in D7, but at this stage that might not be relevant any more.

Proposed resolution

Pass in a title in to the feed_icon template, so the link text makes sense.

I suggest we use the site name for this.

Remaining tasks

  • Update SyndicateBlock.php
  • Check tests

User interface changes

API changes

Data model changes

Release notes snippet

Filename is not shown in the maximum allowed file size error message

$
0
0

Problem/Motivation

When uploading multiple files in a file managed field and one or more files exceed the upload limit, the file name(s) are not shown.

Proposed resolution

The problem is the use of SplFileInfo->getFilename() for the error messages, which is empty. SplFileInfo->getClientOriginalName() should be used, like it is later for the file entity values array.

Remaining tasks

None.

User interface changes

The error message will change from
The file could not be saved because it exceeds 2 MB, the maximum allowed size for uploads.
to
The file BILL FAY - BE NOT SO FEARFUL.mp3 could not be saved because it exceeds 2 MB, the maximum allowed size for uploads.

API changes

None.

Data model changes

None.

Upgrade dependencies prior to 9.1.0

$
0
0

Problem/Motivation

To run on PHP 8, we need to bump, among other things, the version of symfony. See https://github.com/symfony/symfony/issues/36872#issuecomment-653233968

Also we should update our dependencies prior to 9.1.0.

Proposed resolution

Run composer update

Remaining tasks

User interface changes

N/a

API changes

N/a

Data model changes

N/a

Release notes snippet

Dependencies are updated to latest version. See ...generate lock diff at time of 9.1.0.


Ensure all packages in composer.lock are considered for vendor hardening

$
0
0

Problem/Motivation

In #3032686: Remove references to unused packages in Drupal 9's vendor hardening we added a test to ensure that packages that had been removed from composer.lock were also removed from our vendor hardening code.

We can go a step further and ensure that all packages listed in composer.lock are also listed in the vendor hardening code, even if there is nothing to harden; this ensures we have at least considered hardening for any new dependency.

Proposed resolution

Make the test in ComposerIntegrationTest::testVendorCleanup() stricter.

Remaining tasks

Decide if this is a good idea.

User interface changes

API changes

Data model changes

Release notes snippet

FieldItemNormalizer to not flatten if one property and getMainPropertyName is NULL

$
0
0

Problem/Motivation

JSON:API has a nice feature in that it flattens a Drupal field value so we don't have pesky value sub-properties on things like string, boolean, email, etc fields. This is great, except when you want your field type to have a forced sub-property.

In the Commerce API module being developed we have a billing_information field that has at least an address property and may have more, such as a tax number or phone number.

Currently, the billing_information field just displays all of the address item values as root properties, causing a broken schema.

The relevant code is: https://git.drupalcode.org/project/drupal/blob/8.8.x/core/modules/jsonap...

      $field_properties = TypedDataInternalPropertiesHelper::getNonInternalProperties($field_item);
      // Flatten if there is only a single property to normalize.
      $values = static::rasterizeValueRecursive(count($field_properties) == 1 ? reset($values) : $values);

getNonInternalProperties will return properties that are not computed or marked internal.

I had to make this workaround for myself:

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    assert($object instanceof Address);
    // Work around for JSON:API's normalization of FieldItems. If there is only
    // one root property in the field item, it will flatten the values. We do
    // not want that for the OrderProfile field, as `address` should be present.
    // This only happens if there is one field on the profile.
    // @see \Drupal\jsonapi\Normalizer\FieldItemNormalizer::normalize
    // @todo open issue FieldItemNormalizer::normalize should ignore if mainPropertyName is NULL.
    $parent = $object->getParent();
    if ($parent instanceof OrderProfile) {
      $field_properties = TypedDataInternalPropertiesHelper::getNonInternalProperties($parent);
      if (count($field_properties) === 1) {
        // This ensures the value is always under an `address` property.
        return ['address' => array_filter($object->getValue())];
      }
    }
    return array_filter($object->getValue());
  }

Proposed resolution

If there is one property returned by TypedDataInternalPropertiesHelper::getNonInternalProperties, check if it matches the main property value. In most cases it will, or getMainPropertyName wil be NULL. If it doesn't match, then do not flatten the field values. Often times getMainPropertyName returns NULL If the field type has multiple properties for its value and there cannot be a single property used (ie: price field, you need the number and currency.)

Remaining tasks

User interface changes

None.

API changes

JSON:API will no longer flatten field types which return NULL or a main property name which does not match the single property returned.

Data model changes

None.

Release notes snippet

Remove redirect to front page after submitting contact form

RouteProvider::getRouteCollectionForRequest() can poison query string of next request

$
0
0

Problem/Motivation

Requests have their query parameters overridden by RouteProvider::getRouteCollectionForRequest() (here) when a route collection is matched in the cache. This is problematic if the cache entry was saved during a subrequest which alters the original request, specifically DefaultExceptionHtmlSubscriber, which sets two internal query parameters (_exception_statuscode and destination) for the error route.

This is problematic in so far as it's not intuitive behaviour (though this dates back to some early pre-8.0 work; see #2480811: Cache incoming path processing and route matching) but more importantly that the query parameters of later requests are overridden with those in the cache. For a form submission, this would mean the destination is overridden and incorrect, but in the case of a jsonapi path, it also means you get:

Drupal\\Core\\Http\\Exception\\CacheableBadRequestHttpException: The following query parameters violate the JSON:API spec: 'destination', '_exception_statuscode'. in Drupal\\jsonapi\\EventSubscriber\\JsonApiRequestValidator->validateQueryParams()

For instance, a common pattern in OAuth/JWT workflows is that a client will make a request with an existing access token; if it's unsuccessful (e.g., returns 401 - see #2840205: Error messages/codes should be more helpful & match spec.) then the client will attempt to obtain a new access token with a refresh token grant, and retry the original request. In this case, the retried request will fail with the above exception against a jsonapi endpoint as the now-authorized request will have the non-JSON:API spec compliant query string added.

Proposed resolution

The query string recovery from cache has mostly to do with the private files controller; see notes below. However, this issue is sensitive to alterations to the Request object prior to the cache ID generation for the collection cache, earlier even than incoming path processing.

Current thoughts are to not cache the match if we're doing a subrequest (though we currently lack that context as that's information stored in the kernel) or set the format for json:api requests sooner, so as to keep the html exception handler from firing to begin with. Or, something else?

Adjust the route collection cache cid to include the query parameters stored on the Request object after early processing.

Remaining tasks

Subsystem maintainer/core committer review.

User interface changes

None

API changes

None.

Data model changes

None.

Release notes snippet

Not necessary?

Undefined index: entity_id in menu_ui.module

File upload not working if AJAX upload doesn't finish

$
0
0

I am still not sure if this is a bug or I am doing something in a way it's not designed, but it sure feels as a bug.

The issue basically is that I can't upload a file (big enough for this to be reproduceable) unless the upload ajax functionality finishes.

I tried this with 8.6.x (latest dev as of today), no PECL upload progress and disabled big_pipe for testing purposes. This happens on a brand new drupal install locally (no network issues whatsoever).

Steps to reproduce

1. Install blank drupal site
2. add a file field to a content type (basic page for example)
3. select a big file (I am trying with one of ~400mb)
4. Click save before waiting for the throbber to finish.

Expected:

The file to be uploaded

Result:

Node immediately saved without the file.

On the other hand, if you want until the ajax functionality finishes, it does work, so it's no php/local settings issue either.

See screengif of both the not working and working parts.

sub_process should accept passed pipeline value as source

$
0
0

Let's say I have:

  • A source row that contains a TID
  • A process plugin, get_pid, that takes the TID and returns a paragraph ID
  • A destination field that is a reference to a paragraph

I should be able to return ['pid' => value] from the plugin, and do this:

my_paragraph:
  -
    plugin: get_pid
    source: tid
  -
    plugin: sub_process
    target_id: pid

But sub_process seems unable to handle this.


Using @requires extension_name in PHPUnit unit tests fails if extension is not present

$
0
0

Problem/Motivation

If you change * @requires extension yaml to * @requires extension nope in \Drupal\Tests\Component\Serialization\YamlPeclTest and run the test you'll see:

OK, but incomplete, skipped, or risky tests!
Tests: 40, Assertions: 0, Skipped: 7.

THE ERROR HANDLER HAS CHANGED!

Other deprecation notices (2)

  1x: The "Drupal\Tests\Listeners\DrupalListener" class implements "PHPUnit\Framework\TestListener" that is deprecated Use the `TestHook` interfaces instead.

  1x: The "Drupal\Tests\Listeners\DrupalListener" class uses "PHPUnit\Framework\TestListenerDefaultImplementation" that is deprecated The `TestListener` interface is deprecated.

Process finished with exit code 1

The problem is the test is marked as failed because THE ERROR HANDLER HAS CHANGED! is outputted from \Symfony\Bridge\PhpUnit\DeprecationErrorHandler::shutdown(). This happens when the error handler that's registered in \Drupal\Tests\Listeners\DeprecationListenerTrait::registerErrorHandler() is not removed.

Proposed resolution

Remaining tasks

User interface changes

None

API changes

None (hopefully)

Data model changes

None

Release notes snippet

Allow Twig templates to use front matter for metadata support

$
0
0

Problem/Motivation

It is becoming increasingly clear, both throughout core and in contrib, that Twig templates need the ability to associate contextual metadata with them.

Typically, in the past, this has been done using standalone/custom YAML files (like with layouts: *.layouts.yml). Previously, in the case of help_topics this metadata was being embedded using HTML <meta> tags inside the templates themselves (this has since been switched to using a stand-alone front matter implementation in anticipation of this issue).

While this technically works and is filtered out during XSS processing, it creates yet another coding paradigm FE developers have to be aware of. The primary reason this was done was to keep the relevant information with the template it is associated with.

From @alexpott in #2920309-321: Add experimental module for Help Topics:

Having to define a help topic in both a yaml file and then create a separate twig template was bothering me. The reason we went for annotations was to keep the discovery along with the code. I think the same rule appears here.

Suffice it to say: we need a standardized way of associating inline metadata with templates.

Potential existing use cases

Being able to associate metadata with a template can also lend to newer innovations for problems we've had in the past.

Potiential new use cases

There are many ideas of how we can help alleviate BC issues with Twig templates, almost all would likely require the ability to provide some sort of metadata with them; if only for some sort of identification, filtering, or sorting purposes.

Proposed resolution

Allow the use of Front Matter YAML blocks at the top of template files.

Front Matter was made popular by Jekyll and has since become sort of the "industry standard" way of associating metadata with any sort of document.

Remaining tasks

  • Create patch
  • Create tests

Note that the framework manager review of this approach was done in comment #160. The framework managers decided that this approach (putting the front matter in YAML format at the top of files, and not enclosing it in comments or other delimeters) was the best approach to use. There was a lot of discussion of the pros and cons of this and other approaches... There was an attempt at a summary in comment #134, and then a bunch of additional discussion, then another summary in comment #157.

User interface changes

None

API changes

None

Data model changes

None

Release notes snippet

A new component has been created to parse front matter from sources. See the change record for more information.

MachineName migrate process plugin should make allowed characters regular expression configurable

$
0
0

Problem/Motivation

The machine_name migrate process plugins replaces all non alphanumeric characters with underscores. It would be great if that would be a bit more flexible. Concretely, for some machine names it makes sense to allow a period as part of the name which currently gets replaced.

The code that currently handles this is the following:

    $new_value = preg_replace('/[^a-z0-9_]+/', '_', $new_value);

Proposed resolution

Add some configuration value to the plugin for this. Not sure whether the whole regular expression, i.e. [^a-z0-9]+ should be configurable or just the character range, i.e. a-z0-9_.

User::setExistingPassword() does not return $this for chaining

$
0
0

The documentation for \Drupal\user\UserInterface::setExistingPassword states that the $this is the return value:

  /**
   * Sets the existing plain text password.
   *
   * Required for validation when changing the password, name or email fields.
   *
   * @param string $password
   *   The existing plain text password of the user.
   *
   * @return $this
   */
  public function setExistingPassword($password);

However, \Drupal\user\Entity\User::setExistingPassword does not return a value:

  /**
   * {@inheritdoc}
   */
  public function setExistingPassword($password) {
    $this->get('pass')->existing = $password;
  }

I'll add a patch to the comments.

Entity reference fields can easily become stale (b/c of DataReferenceBase)

$
0
0

Entity reference fields internally use \Drupal\Core\Entity\Plugin\DataType\EntityReference, which extends \Drupal\Core\TypedData\DataReferenceBase. However, neither DataReferenceBase nor EntityReference have a way to clear its $target property. This leads to entity reference fields becoming stale as soon as the target entity changes.

See the following scenario:

$node_storage = $entity_type_manager->getStorage('node');
$node_type_storage = $entity_type_manager->getStorage('node_type');

$node = $node_storage->load(1);
echo $node->type->entity->label(); // Hello world!

$node_type = $node_type_storage->load('hello_world');
$node_type->name = 'Hello moon!";
$node_type_storage->save($node_type);

// Reference's "target" property is stale.
echo $node->type->entity->label(); // Hello world!

// Storage thinks node is unchanged so returns node with stale reference.
$node = $node_storage->load(1);
echo $node->type->entity->label(); // Hello world!

// Storage returns new copy of the node, so the reference target is unset and needs to be loaded.
$node = $node_storage->loadUnchanged(1);
echo $node->type->entity->label(); // Hello moon!

I was wondering if we should replace the property with a static cache that uses the target entity's cache tags.

Viewing all 294899 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>