Is there a way or is it currently possible to add an entity reference field to a content type that references config pages?

Thanks in advance!

CommentFileSizeAuthor
#6 config_page_reference_in_nodes.patch2.41 KBvitaliiishchenko
#2 3.png25.28 KBshumer
#2 2.png32.15 KBshumer
#2 1.png34.52 KBshumer
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marknatividad created an issue. See original summary.

shumer’s picture

Issue summary: View changes
StatusFileSize
new34.52 KB
new32.15 KB
new25.28 KB

Hey, probably you would need to do something like that

Step 1
Step 2
Step 3

marknatividad’s picture

Thanks @shumer, I think that allows the reference to be made to the config page type configuration. Is there a way to reference the actual content of a config page?

marknatividad’s picture

Looking at the module code, a decision was made to remove config pages from the dropdown select.. I wonder what the reason was?

/**
 * Implements hook_form_FORM_ID_alter().
 */
function config_pages_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  // Config pages is a specific type of entity so we want to remove it from
  // select.
  $element = &$form['settings']['target_type'];
  if (!empty($element['#options'])) {
    foreach ($element['#options'] as $key => $val) {
      if (is_array($element['#options'][$key]) && isset($element['#options'][$key]['config_pages'])) {
        unset($element['#options'][$key]['config_pages']);
      }
    }
  }
}
shumer’s picture

The ConfigPage is not a usual entity from a Drupal perspective. There is a specific property caleed "Context" exists, so if you'll reference to a entity itself you won't be able to load a proper data when context is changed (for exapmle language or domain). Hence, this type of reference is unavailbale.
If I were you I probably still make a reference to a Type itself as of my first comment. But also you can create a field formatter which will load a proper ConfigPage for required type. This probably can be added to a module, so if you want to introduce a patch feel free to do it.

vitaliiishchenko’s picture

Assigned: Unassigned » vitaliiishchenko
Status: Active » Patch (to be ported)
StatusFileSize
new2.41 KB

I added a field formatter which loads a proper ConfigPage for required node type.

miritas made their first commit to this issue’s fork.

miritas’s picture

I've checked the patch on clean Drupal installation. Works ok for me.
However, I've replaced the use of a static method call with a non-static. The changes have been pushed to Gitlab.

miritas’s picture

Status: Patch (to be ported) » Needs review

shumer’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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