Error: Undefined constant "Drupal\google_index_api\Form\FILE_STATUS_PERMANENT"

Created on 26 July 2023, over 1 year ago
Updated 28 July 2023, over 1 year ago

Problem/Motivation

After submitting the configuration form, the following error pops up:

Error: Undefined constant "Drupal\google_index_api\Form\FILE_STATUS_PERMANENT" in Drupal\google_index_api\Form\SettingsForm->submitForm() (line 133 of modules/contrib/google_index_api/src/Form/SettingsForm.php).

Because FILE_STATUS_PERMANENT is deprecated

Proposed resolution

Change FILE_STATUS_PERMANENT for FileInterface::STATUS_PERMANENT in google_index_api/src/Form/SettingsForm.php:

Before:

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Grab the values.
    $fid = $form_state->getValue('google_index_api_json_file');
    $domain = $form_state->getValue('google_index_api_base_domain');

    // Make the file perm.
    if (isset($fid[0])) {
      $file = File::load($fid[0]);
      if ($file !== NULL) {
        $file->status = FILE_STATUS_PERMANENT;
        $file->save();
...

After:

use Drupal\file\FileInterface;
...

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Grab the values.
    $fid = $form_state->getValue('google_index_api_json_file');
    $domain = $form_state->getValue('google_index_api_base_domain');

    // Make the file perm.
    if (isset($fid[0])) {
      $file = File::load($fid[0]);
      if ($file !== NULL) {
        $file->status = FileInterface::STATUS_PERMANENT;
        $file->save();
πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain taote

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

Comments & Activities

Production build 0.71.5 2024