Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix config schema issues #46

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions message_ui.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@
* message_ui.install
*/

use Drupal\message\Entity\MessageTemplate;
use Drupal\message_ui\MessageUIHelper;

/**
* Implements hook_install().
*/
function message_ui_install() {
// Set the fields for the of the message form.
$templates = \Drupal::entityTypeManager()->getStorage('message_template')->loadMultiple();

/** @var \Drupal\message_ui\MessageUIFieldDisplayManagerServiceInterface $message_ui_field_display_manager */
$message_ui_field_display_manager = \Drupal::service('message_ui.field_display_manager');
foreach (array_keys($templates) as $template) {
$message_ui_field_display_manager->setFieldsDisplay($template);
foreach (MessageTemplate::loadMultiple() as $template_id => $template) {
MessageUIHelper::addEntityFormDisplay($template_id);
}

}

/**
Expand Down
25 changes: 3 additions & 22 deletions message_ui.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* Contains Drupal\message_ui\message_ui.module.
*/

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\message\Entity\Message;
use Drupal\message_ui\Plugin\QueueWorker\MessageArgumentsWorker;
use Drupal\Core\Url;

/**
* Grant permission for the operation upon message.
Expand All @@ -22,24 +22,6 @@ const MESSAGE_UI_ALLOW = TRUE;
*/
const MESSAGE_UI_DENY = TRUE;

/**
* Implements hook_entity_insert().
*/
function message_ui_entity_insert(EntityInterface $entity) {

if ($entity->getEntityTypeId() != 'field_config') {
return;
}

if ($entity->get('entity_type') != 'message') {
return;
}

// A new field was attached to the message template. We will make sure it will
// appear in message form.
\Drupal::service('message_ui.field_display_manager')->SetFieldsDisplay($entity->get('bundle'));
}

/**
* Implements hook_entity_base_field_info_alter().
*
Expand All @@ -61,10 +43,9 @@ function message_ui_entity_base_field_info_alter(&$fields, EntityTypeInterface $
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'#group' => 'advanced',
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'size' => 60,
'placeholder' => '',
],
])
Expand Down
3 changes: 0 additions & 3 deletions message_ui.services.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
message_ui.field_display_manager:
class: Drupal\message_ui\MessageUIFieldDisplayManagerService
arguments: ['@entity_type.manager']
plugin.manager.message_ui_views_contextual_links:
class: Drupal\message_ui\MessageUiViewsContextualLinksManager
parent: default_plugin_manager
58 changes: 0 additions & 58 deletions src/MessageUIFieldDisplayManagerService.php

This file was deleted.

20 changes: 0 additions & 20 deletions src/MessageUIFieldDisplayManagerServiceInterface.php

This file was deleted.

29 changes: 29 additions & 0 deletions src/MessageUIHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Drupal\message_ui;

use Drupal\Core\Entity\Entity\EntityFormDisplay;

/**
* Provide reusable methods.
*/
class MessageUIHelper {

/**
* Adds a new entity form display if it doesn't exist.
*
* @param string $template
* The message template ID.
*/
public static function addEntityFormDisplay($template) {
if (!EntityFormDisplay::load("message.{$template}.default")) {
EntityFormDisplay::create([
'targetEntityType' => 'message',
'bundle' => $template,
'mode' => 'default',
'status' => TRUE,
])->save();
}
}

}