Remove file_entity_entity_base_field_info()

Created on 24 January 2016, almost 9 years ago
Updated 19 April 2024, 8 months ago

Problem/Motivation

Once #2655780: Allow to configure entity types to add path base fields (so that Pathauto can apply for them) is in, we'll no longer need a custom hook_base_field_info() implementation to add the path field.

Proposed resolution

Remove it, update the test to set the necessary configuration instead.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Postponed: needs info

Version

2.0

Component

Code

Created by

🇨🇭Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    The patch applies although when running the database update 8201, it generates the following errors:

    Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck().

  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    If accessCheck(TRUE) is inserted into the relevant query in the file_entity.install file, then the update runs fine:

    /**
     * Update pathauto to enable path field for file entity type if there are
     * file aliases or patterns.
     */
    function file_entity_update_8201() {
      if (\Drupal::moduleHandler()->moduleExists('pathauto')) {
        $file_patterns = \Drupal::entityTypeManager()->getStorage('pathauto_pattern')->loadByProperties(['type' => 'canonical_entities:file']);
        $file_aliases = \Drupal::entityTypeManager()->getStorage('path_alias')->getQuery()->condition('path', '/file/%', 'LIKE')->accessCheck(TRUE)->count()->execute();
        if (!empty($file_patterns) || $file_aliases > 0) {
          $config_factory = \Drupal::configFactory();
          $config = $config_factory->getEditable('pathauto.settings');
          $enabled_entity_types = $config->get('enabled_entity_types');
          $config->set('enabled_entity_types', array_unique(array_merge($enabled_entity_types, ['file'])));
          $config->save();
        }
        else {
          \Drupal::messenger()->addMessage(t("Files no longer have an alias field by default, enable it in the pathauto settings if you wish to use that."));
        }
      }
    }
    
    
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    32 pass
  • 🇬🇧United Kingdom robcarr Perthshire, Scotland

    Updated patch attached

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom steven jones
    +++ b/file_entity.install
    @@ -197,3 +197,24 @@ function file_entity_update_8005() {
    +    $file_patterns = \Drupal::entityTypeManager()->getStorage('pathauto_pattern')->loadByProperties(['type' => 'canonical_entities:file']);
    +    $file_aliases = \Drupal::entityTypeManager()->getStorage('path_alias')->getQuery()->condition('path', '/file/%', 'LIKE')->accessCheck(TRUE)->count()->execute();
    

    You'd actually want ->accessCheck(FALSE)

    Because you don't want the access checking enabled for this query.

  • First commit to issue fork.
  • 🇮🇳India bharath-kondeti Hyderabad

    Updated the patch addressing #23. Please review

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    32 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    32 pass
  • @bharath-kondeti opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada joseph.olstad

    Review so far:
    I grepped all Drupal 8 projects using grep . xnddx . ru , currently only the file_entity is using this api function name .

    It's likely a save change to make above, thanks for your work.

  • Assigned to berdir
  • Status changed to RTBC over 1 year ago
  • 🇬🇧United Kingdom c_archer Cumbria

    Tested patch on #25 and it worked as hoped.

  • Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    Waiting for branch to pass
  • 🇨🇦Canada joseph.olstad

    Gitlab didn't use the commit message I specified, grumble.

    Should have been this:
    git commit -m 'Issue #2655844 by rutiolma, bharath-kondeti, Berdir, robcarr, joseph.olstad, Steven Jones, c_archer: Remove file_entity_entity_base_field_info()' --author="Sascha Grossenbacher <5019-berdir@users.noreply.drupalcode.org>"

  • Status changed to Fixed about 1 year ago
  • 🇨🇦Canada joseph.olstad

    Included in rc2

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States webdrips

    I'm not sure if it's best to start a new issue or use this one, but after upgrading to RC2 and running the database updates, I'm noticing the following:

    ENTITY/FIELD DEFINITIONS
    Mismatched entity and/or field definitions
    The following changes were detected in the entity type and field definitions.
    File
    The URL alias field needs to be uninstalled.
    

    This was the only update I applied, so I don't see how this error could've come from anywhere else.

    I tried uninstalling this module and reinstalling it (after running Cron), and the same for pathauto, but I can't seem to get rid of this message.

  • 🇨🇦Canada paintingguy

    I have the same issue as @webdrips after updating to rc2

  • Issue was unassigned.
  • Status changed to Active about 1 year ago
  • 🇨🇦Canada joseph.olstad

    reverting this, a new release to follow

  • Status changed to Postponed: needs info about 1 year ago
  • 🇺🇸United States webdrips

    RC4 Removed the Status Report error message for me.

  • 🇬🇧United Kingdom steven jones

    RC4 added it back for me, this patch removed it.

    @webdrips I wonder if you want a URL alias field on your files? Maybe we need to be smarter about when the base field is declared, are you also using the latest versions of pathauto?

Production build 0.71.5 2024