get settings recognised

Created on 10 September 2024, 2 months ago

Problem/Motivation

How to get the settings in migrate_skip_fields.settings.php into the parameter Settings $settings in the __construct() for MigrateSkipFieldsByName class?
Does it need a ~.settings.schema.yml file and what would that look like?

💬 Support request
Status

Active

Version

1.0

Component

Documentation

Created by

🇳🇿New Zealand scrypter

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

Comments & Activities

  • Issue created by @scrypter
  • 🇮🇳India zartab farooquee

    Creating a migrate_skip_fields/src/MigrateSkipFieldsByName.php

    namespace Drupal\migrate_skip_fields;

    use Drupal\Core\Config\ConfigFactoryInterface;

    class MigrateSkipFieldsByName {
    protected $settings;

    public function __construct(ConfigFactoryInterface $config_factory) {
    $this->settings = $config_factory->get('migrate_skip_fields.settings')->get('skip_fields');
    }
    }

    Then i created migrate_skip_fields/config/install/migrate_skip_fields.settings.yml

    migrate_skip_fields.settings:
    type: config_object
    label: 'Migrate Skip Fields Settings'
    mapping:
    skip_fields:
    type: string
    label: 'Skip Fields'
    description: 'Comma-separated list of fields to skip during migration.'

    We access settings using ConfigFactoryInterface in the class. The schema file helps validate the settings, and managing everything in a custom module keeps it clean and modular.

  • Status changed to Postponed: needs info 11 days ago
  • 🇳🇮Nicaragua dinarcon

    I think the original question is related to where the settings used by the module should be placed. That would be sites/default/settings.php or another file included there. The module provided migrate_skip_fields.settings.php file is meant to serve only as a reference of how to set the values, but the settings themselves would live in the standard location.

    @scrypter you can instruct sites/default/settings.php to read migrate_skip_fields.settings.php from a custom module, but that would not be standard. Alternatively, you can copy the file into the sites/default/ folder and include it by adding this to sites/default/settings.php:

    
    if (file_exists($app_root . '/' . $site_path . '/migrate_skip_fields.settings.php')) {
      include $app_root . '/' . $site_path . '/migrate_skip_fields.settings.php';
    }
    

    The module does not use the configuration management API nor makes use of configuration scheme.

    @zartab farooquee I am not clear what you are suggesting nor how the code is related the module's functionality.

    Updating status. Please change back to active and add more context if I have not addressed the questions.

Production build 0.71.5 2024