Skip to content

Commit

Permalink
Merge pull request linnovate#66 from istolar/OI-74-automatically-foll…
Browse files Browse the repository at this point in the history
…ow-group-ideas

OI-74 Automatically follow group ideas.
  • Loading branch information
db-Matroskeen authored Jun 30, 2020
2 parents f990f7b + 9428ae4 commit 719a272
Show file tree
Hide file tree
Showing 20 changed files with 349 additions and 55 deletions.
3 changes: 2 additions & 1 deletion config/install/core.entity_view_display.node.faq.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ content:
region: content
settings: { }
third_party_settings: { }
hidden: { }
hidden:
addtoany: true
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ content:
third_party_settings: { }
region: content
hidden:
addtoany: true
field_faq_items: true
5 changes: 3 additions & 2 deletions config/install/core.entity_view_display.node.page.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ content:
settings: { }
third_party_settings: { }
region: content
field_paragraphs:
type: entity_reference_revisions_entity_view
field_attached_docs:
weight: 104
label: above
Expand All @@ -118,6 +116,9 @@ content:
third_party_settings: { }
type: image
region: content
field_paragraphs:
type: entity_reference_revisions_entity_view
region: content
links:
weight: 101
region: content
Expand Down
9 changes: 9 additions & 0 deletions config/install/core.entity_view_mode.vote.token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies:
module:
- votingapi
id: vote.token
label: Token
targetEntityType: vote
cache: true
9 changes: 9 additions & 0 deletions config/install/core.entity_view_mode.vote_result.token.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
langcode: en
status: true
dependencies:
module:
- votingapi
id: vote_result.token
label: Token
targetEntityType: vote_result
cache: true
4 changes: 2 additions & 2 deletions config/install/group.type.idea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies: { }
id: idea
label: Idea
description: 'It provides an idea group type.'
creator_membership: true
creator_wizard: true
creator_membership: false
creator_wizard: false
creator_roles:
- idea-author
14 changes: 14 additions & 0 deletions config/install/image.style.mentions_icon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
langcode: en
status: true
dependencies: { }
name: mentions_icon
label: 'CKEditor Mentions Icon'
effects:
fa871714-f0f7-48fb-9ae7-e0b9bea3318f:
uuid: fa871714-f0f7-48fb-9ae7-e0b9bea3318f
id: image_scale_and_crop
weight: 0
data:
width: 20
height: 20
anchor: center-center
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
langcode: en
status: true
dependencies:
config:
- node.type.idea
dependencies: { }
id: node_type_idea
action: display_page
allow_override: 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
langcode: en
status: true
dependencies:
config:
- taxonomy.vocabulary.idea_lifecycle_phase
dependencies: { }
id: taxonomy_vocabulary_idea_lifecycle_phase
action: access_denied
allow_override: 0
Expand Down
59 changes: 59 additions & 0 deletions config/install/rules.reaction.follow_idea_after_joining_group.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
langcode: en
status: true
dependencies: { }
id: follow_idea_after_joining_group
label: 'Set the user to follow the idea after joining the group.'
events:
-
event_name: openideal_user.user_joined_group
description: ''
tags: { }
config_version: '3'
expression:
id: rules_rule
uuid: 4da5c6e8-b04c-4008-ab13-e3451492b751
weight: 0
conditions:
id: rules_and
uuid: 0f2245d4-056b-41b8-a54d-bbfac43c0efb
weight: 0
conditions:
-
id: rules_condition
uuid: 566fa3aa-9839-4a88-804e-86bce6911194
weight: 0
context_values:
operation: '=='
value: idea
context_mapping:
data: node.type.target_id
context_processors:
operation:
rules_tokens: { }
value:
rules_tokens: { }
provides_mapping: { }
condition_id: rules_data_comparison
negate: false
actions:
id: rules_action_set
uuid: 7db1f1f7-b94d-4422-a7e1-f46ee3654d33
weight: 0
actions:
-
id: rules_action
uuid: ac82e6de-b6a8-4712-ac71-87101858a0ba
weight: 0
context_values:
operation: flag
flag_id: follow
context_mapping:
entity: node
user: user
context_processors:
operation:
rules_tokens: { }
flag_id:
rules_tokens: { }
provides_mapping: { }
action_id: openideal_user_flag_action
2 changes: 1 addition & 1 deletion config/install/user.role.authenticated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ permissions:
- 'post comments'
- 'search content'
- 'skip comment approval'
- 'use inline mentions'
- 'use life_cycle_phases transition create_new_draft'
- 'use life_cycle_phases transition publish'
- 'use inline mentions'
- 'use text format basic_html'
- 'use text format comments'
4 changes: 2 additions & 2 deletions config/install/user_registrationpassword.mail_original.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
status_activated:
subject: 'Account details for [user:display-name] at [site:name] (approved)'
body: "[user:display-name],\r\n\r\nYour account at [site:name] has been activated.\r\n\r\nYou may now log in by clicking this link or copying and pasting it into your browser:\r\n\r\n[user:one-time-login-url]\r\n\r\nThis link can only be used once to log in and will lead you to a page where you can set your password.\r\n\r\nAfter setting your password, you will be able to log in at [site:login-url] in the future using:\r\n\r\nusername: [user:account-name]\r\npassword: Your password\r\n\r\n-- [site:name] team"
subject: 'Account details for [user:display-name] at [site:name]'
body: "[user:display-name],\n\nYour account at [site:name] has been activated.\n\nYou will be able to log in to [site:login-url] in the future using:\n\nusername: [user:name]\npassword: your password.\n\n-- [site:name] team"
langcode: en
4 changes: 2 additions & 2 deletions modules/openideal_challenge/openideal_challenge.module
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use Drupal\views\ViewExecutable;
function openideal_challenge_cron() {
// Processing open/close scheduling challenge nodes via cron.
/** @var \Drupal\openideal_challenge\Service\OpenidealChallengeService $challenge_service */
$challenge_service = Drupal::service('openideal_challenge.challenge_service');
$challenge_service = \Drupal::service('openideal_challenge.challenge_service');
$challenge_service->openChallenges();
$challenge_service->closeChallenges();
}
Expand Down Expand Up @@ -82,7 +82,7 @@ function openideal_challenge_views_query_alter(ViewExecutable $view, QueryPlugin
*/
function openideal_challenge_node_presave(EntityInterface $entity) {
if ($entity->bundle() == 'challenge') {
$event_dispatcher = Drupal::service('event_dispatcher');
$event_dispatcher = \Drupal::service('event_dispatcher');
// If challenge was created react only on if it was opened
// make no sense to react on close.
if ($entity->isNew() && $entity->get('field_is_open')->value) {
Expand Down
40 changes: 30 additions & 10 deletions modules/openideal_idea/openideal_idea.module
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use Drupal\openideal_idea\Form\OpenidealBaseRatingForm;
function openideal_idea_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'node_idea_form') {
// Check challenge query parameter.
if ($challenge_id = Drupal::request()->get('challenge')) {
if ($challenge_id = \Drupal::request()->get('challenge')) {
// Load predefined challenge node.
$predefined_challenge = Drupal::entityTypeManager()
$predefined_challenge = \Drupal::entityTypeManager()
->getStorage('node')
->load($challenge_id);
if (!empty($predefined_challenge)) {
Expand All @@ -46,6 +46,12 @@ function openideal_idea_form_alter(&$form, FormStateInterface $form_state, $form
unset($form['group_roles']['widget']['#options']['idea-author']);
unset($form['group_roles']['widget']['#options']['idea-expert']);
}

// Unset useless group roles for group idea membership edit form.
if ($form_id == 'group_content_idea-group_membership_edit_form') {
unset($form['group_roles']['widget']['#options']['idea-author']);
}

}

/**
Expand All @@ -63,25 +69,39 @@ function openideal_idea_node_presave(NodeInterface $node) {
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function openideal_idea_node_insert(EntityInterface $entity) {
function openideal_idea_node_insert(NodeInterface $entity) {
if ($entity->bundle() == 'idea') {
try {
// Create the group for the node.
/** @var \Drupal\group\Entity\Group $group */
$group = Drupal::entityTypeManager()->getStorage('group')
$group = \Drupal::entityTypeManager()->getStorage('group')
->create([
'label' => $entity->label(),
'type' => 'idea',
'langcode' => 'en',
]);
$group->save();

// Need to add node to group before the member will be added
// to be able fetch the node.
//
// Define the plugin id.
$plugin_id = 'group_node:' . $entity->bundle();
// Add the entity to the group.
$group->addContent($entity, $plugin_id);

// The group creator automatically becomes a member.
$values = ['group_roles' => ['idea-author']];
$group->addMember($group->getOwner(), $values);

// Author follow the node after its creating.
/** @var \Drupal\flag\FlagService $flag_service*/
$flag_service = \Drupal::service('flag');
$flag = $flag_service->getFlagById('follow');
$flag_service->flag($flag, $entity, $entity->getOwner());
}
catch (Exception $e) {
Drupal::logger('openideal_idea')->error($e->getMessage());
\Drupal::logger('openideal_idea')->error($e->getMessage());
}
}
}
Expand Down Expand Up @@ -115,7 +135,7 @@ function openideal_idea_entity_access(EntityInterface $entity, $operation, Accou
*/
function openideal_idea_comment_create_access(AccountInterface $account, array $context, $entity_bundle) {
/** @var \Drupal\node\NodeInterface $node */
$node = Drupal::routeMatch()->getParameter('node');
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof NodeInterface && $node->bundle() === 'idea') {
return AccessResult::forbiddenIf(!$node->get('field_duplicate_of')->isEmpty());
}
Expand All @@ -129,15 +149,15 @@ function openideal_idea_menu_local_tasks_alter(&$data, $route_name, RefinableCac
return;
}

$node = Drupal::routeMatch()->getParameter('node');
$node = \Drupal::routeMatch()->getParameter('node');
if ($node->bundle() === 'idea' && $group = _openideal_idea_get_group_by_entity($node)) {
$data['tabs'][0]['group.members'] = [
'#theme' => 'menu_local_task',
'#link' => [
'title' => t('Group Members'),
'url' => Url::fromRoute('view.group_members.page_1', ['group' => $group->id()]),
],
'#access' => $group->hasPermission('administer members', Drupal::currentUser()),
'#access' => $group->hasPermission('administer members', \Drupal::currentUser()),
];

// The tab we're adding is dependent on a user's access to add content.
Expand All @@ -157,7 +177,7 @@ function openideal_idea_menu_local_tasks_alter(&$data, $route_name, RefinableCac
function _openideal_idea_get_group_by_entity($entity) {
// In our case we will have one node per group.
// We get all group ids but return just the first one.
$group_contents = Drupal::entityTypeManager()
$group_contents = \Drupal::entityTypeManager()
->getStorage('group_content')
->loadByEntity($entity);
foreach ($group_contents as $group_content) {
Expand All @@ -183,7 +203,7 @@ function openideal_idea_form_views_exposed_form_alter(&$form, FormStateInterface
unset($form['phase']['#options']['Life Cycle Phases']);
}
// Get the list of published and opened challenges.
$node_storage = Drupal::entityTypeManager()->getStorage('node');
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$query = $node_storage->getQuery()
->condition('type', 'challenge', '=')
->condition('field_is_open', TRUE, '=')
Expand Down
11 changes: 5 additions & 6 deletions modules/openideal_idea/src/ComputedNumberList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\openideal_idea;

use Drupal;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
use InvalidArgumentException;
Expand All @@ -28,19 +27,19 @@ protected function computeValue() {
* Get overall score.
*/
protected function getOverallScore() {
$configuration = Drupal::configFactory()->get('openideal_idea.scoreconfig');
$configuration = \Drupal::configFactory()->get('openideal_idea.scoreconfig');
// Node id.
$id = $this->getEntity()->id();

// Get node comments.
$comments = Drupal::entityQuery('comment')
$comments = \Drupal::entityQuery('comment')
->condition('entity_id', $id)
->condition('entity_type', 'node')
->count()
->execute();

// Get node votes.
$votes = Drupal::entityQuery('vote')
$votes = \Drupal::entityQuery('vote')
->condition('entity_id', $id)
->condition('entity_type', 'node')
->count()
Expand All @@ -50,9 +49,9 @@ protected function getOverallScore() {
$node_counter_value = 0;

// If statistics module is enabled then add node view count to score.
if (Drupal::moduleHandler()->moduleExists('statistics')) {
if (\Drupal::moduleHandler()->moduleExists('statistics')) {
/** @var \Drupal\statistics\StatisticsViewsResult $statistics_result */
$statistics_result = Drupal::service('statistics.storage.node')->fetchView($id);
$statistics_result = \Drupal::service('statistics.storage.node')->fetchView($id);
if ($statistics_result) {
$node_counter_value = $statistics_result->getTotalCount() * ($configuration->get('node_value') ?? 0.2);
}
Expand Down
3 changes: 0 additions & 3 deletions modules/openideal_idea/src/Form/ScoreConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;

/**
* Class ScoreConfigForm.
Expand Down
Loading

0 comments on commit 719a272

Please sign in to comment.