Fix hook_update_N docs for display of code block, remove unnecessary @see

Created on 12 July 2024, 3 months ago
Updated 2 August 2024, 3 months ago

Problem/Motivation

hook_update_N documentation is not displaying correctly.

This is not on api.drupal.org yet. This is from my local install of the API project.
The code block:

 At the moment we need to add defensive coding in the future update to ensure it is skipped. @code function my_module_update_11101() { $equivalent_update = \Drupal::service('update.update_hook_registry')->getEquivalentUpdate(); if ($equivalent_update instanceof \Drupal\Core\Update\EquivalentUpdate) { return $equivalent_update->toSkipMessage(); }

// The rest of the update function. } @encode

This is what is shown on api.drupal.org. Below the paragraph starting 'The numbers' is in the 'See also' section and it should not be.

See also

hook_update_last_removed()

The numbers are normally composed of three parts:

    1 or 2 digits for Drupal core compatibility (Drupal 8, 9, 10, etc.). This convention must be followed. If your module is compatible with multiple major versions (e.g., it has a core_version_requirement of '^8.8 || ^9'), use the lowest major core branch it is compatible with (8 in this example).
    1 or 2 digits for your module's major release version. Examples:
        For 8.x-1.* or 1.y.x (semantic versioning), use 1 or 01.
        For 8.x-2.* or 2.y.x, use 2 or 02.
        For 8.x-10.* or 10.y.x, use 10.
        For core 8.0.x, use 0 or 00.
        For core 8.1.x, use 1 or 01.
        For core 8.10.x, use 10.

    This convention is optional but suggested for clarity. Note: While four- digit update Hooks are standard, if you follow the above convention, you may run into the need to start using five digits if you get to a major (or, for core, a minor) version 10. This will work fine; what matters is that you must ALWAYS increase the number when a new update hook is added. For example, if you add hook_update_81001(), you cannot later add hook_update_9101(). Instead, you would need to use hook_update_90101().
    2 digits for sequential counting, starting with 01. Note that the x000 number can never be used: the lowest update number that will be recognized and run is 8001.

Batch operations

Steps to reproduce

Proposed resolution

Remove the @see. It is already listed later in the file

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Fixed

Version

11.0 πŸ”₯

Component
Database updateΒ  β†’

Last updated 10 days ago

No maintainer
Created by

πŸ‡³πŸ‡ΏNew Zealand quietone

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

Merge Requests

Comments & Activities

  • Issue created by @quietone
  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    After the change the code block is

     At the moment we need to add defensive coding in the future update to ensure it is skipped.
    
    function my_module_update_11101() {
        $equivalent_update = \Drupal::service('update.update_hook_registry')->getEquivalentUpdate();
        if ($equivalent_update instanceof \Drupal\Core\Update\EquivalentUpdate) {
            return $equivalent_update->toSkipMessage();
        }
        // The rest of the update function.
    }
    
    Parameters

    And the See also section is

    See also
    
    batch
    
    schemaapi
    
    hook_update_last_removed()
    
    update_get_update_list()
    
    \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
    
    https://www.drupal.org/node/2535316

    The paragraph starting 'The numbers' is now correctly in the flow as follows. The function hook_update_last_removed() does display as a link.

    Naming and documenting your function
    
    For each change in a module that requires one or more actions to be performed when updating a site, add a new implementation of hook_update_N() to your my_module.install file (assuming my_module is the machine name of your module). Implementations of hook_update_N() are named (module name)_update_(number).
    
    The number (N) must be higher than hook_update_last_removed().
    
    The numbers are normally composed of three parts:
    
        1 or 2 digits for Drupal core compatibility (Drupal 8, 9, 10, etc.). This convention must be followed. If your module is compatible with multiple major versions (e.g., it has a core_version_requirement of '^8.8 || ^9'), use the lowest major core branch it is compatible with (8 in this example).
        1 or 2 digits for your module's major release version. Examples:
            For 8.x-1.* or 1.y.x (semantic versioning), use 1 or 01.
            For 8.x-2.* or 2.y.x, use 2 or 02.
            For 8.x-10.* or 10.y.x, use 10.
            For core 8.0.x, use 0 or 00.
            For core 8.1.x, use 1 or 01.
            For core 8.10.x, use 10.
    
        This convention is optional but suggested for clarity. Note: While four- digit update hooks are standard, if you follow the above convention, you may run into the need to start using five digits if you get to a major (or, for core, a minor) version 10. This will work fine; what matters is that you must ALWAYS increase the number when a new update hook is added. For example, if you add hook_update_81001(), you cannot later add hook_update_9101(). Instead, you would need to use hook_update_90101().
        2 digits for sequential counting, starting with 01. Note that the x000 number can never be used: the lowest update number that will be recognized and run is 8001.
    
    @todo Remove reference to CORE_MINIMUM_SCHEMA_VERSION (e.g., x001) once https://www.drupal.org/project/drupal/issues/3106712 is resolved.
    
    Examples:
  • Merge request !8748fix hook_update_n docs β†’ (Open) created by quietone
  • Status changed to Needs review 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Adding parent. Not strictly a requirement but one fix is for a typo in πŸ“Œ Handling update path divergence between 11.x and 10.x Fixed which was a requirement.

  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • Status changed to Needs work 3 months ago
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • Status changed to Needs review 3 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    To detect @encode in the future I tried adding @encode to the flagWords list and adding @encode to the file Drupal.php. Unfortunately, the error is not detected. And using \@encode results in Configuration Error: Failed to read config file: "/var/www/html/core/.cspell.json".

    I didn't find anything in the cspell docs for this situation.

  • Status changed to RTBC 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Seems straight forward.

    • catch β†’ committed acd475c7 on 10.3.x
      Issue #3460921 by quietone: Fix hook_update_N docs for display of code...
    • catch β†’ committed 91b3f6f3 on 10.4.x
      Issue #3460921 by quietone: Fix hook_update_N docs for display of code...
    • catch β†’ committed ddd1a2c0 on 11.0.x
      Issue #3460921 by quietone: Fix hook_update_N docs for display of code...
    • catch β†’ committed a7e865b9 on 11.x
      Issue #3460921 by quietone: Fix hook_update_N docs for display of code...
  • Status changed to Fixed 3 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Committed/pushed to 11.x and cherry-picked back through to 10.3.x, thanks!

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

Production build 0.71.5 2024