Commit ba49c337 authored by Gorodkov Denis's avatar Gorodkov Denis

context definition

parent 2e65a9e3
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -186,9 +186,11 @@ function mymodule_node_access(\Drupal\Core\Entity\EntityInterface $node, $operat
}
}
function mymodule_node_presave($node) {
/**
* Implements hook_node_insert()
*/
function mymodule_node_insert(Drupal\Core\Entity\EntityInterface $node) {
$user = Drupal::currentUser();
$user_roles = $user->getRoles();
$isRedactor = false;
foreach ($user_roles as $role) {
......@@ -198,12 +200,6 @@ function mymodule_node_presave($node) {
}
if ($isRedactor) {
if ($node->hasField('field_editor')) {
$editors = $node->get("field_editor")->referencedEntities();
foreach ($editors as $editor) {
if ($editor->id() == $user->id()) {
return true;
}
}
$node->field_editor[] = $user->id();
}
}
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
<?php
namespace Drupal\mymodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;
/**
* Provides
*
* @Block(
* id = "test_context_definition",
* admin_label = @Translation("Test block with context_definition"),
* context_definitions = {
* "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node")),
* "term" = @ContextDefinition("entity:taxonomy_term", required = FALSE, label = @Translation("Term")),
* }
* )
*/
class ContextDefinition extends BlockBase {
public function build() {
$node = $this->getContextValue('node');
$term = $this->getContextValue('term');
empty($node) ? $entiy = $term : $entiy = $node;
empty($node) ? $entiy_type_id = 'taxonomy_term' : $entiy_type_id = 'node';
$build = \Drupal::entityTypeManager()->getViewBuilder($entiy_type_id)->view($entiy, 'teaser');
$tags = $entiy->getCacheTags();
foreach ($tags as $tag) {
$build['#cache']['tags'][] = $tag;
}
return $build;
}
}
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment