瀏覽代碼

added create operation to user connexion block

bach 1 年之前
父節點
當前提交
a354c2a7fe
共有 1 個文件被更改,包括 45 次插入0 次删除
  1. 45 0
      web/themes/custom/reha/reha.theme

+ 45 - 0
web/themes/custom/reha/reha.theme

@@ -1,5 +1,11 @@
 <?php
 
+
+use Drupal\Core\Url;
+use Drupal\Core\Link;
+use Drupal\Core\Render\Markup;
+
+
 /**
  * @file
  * Functions to support theming in the reha theme.
@@ -34,3 +40,42 @@ function reha_preprocess_node(&$variables) {
 
 
 
+/**
+ * Prepares variables for block templates.
+ *
+ * Default template: block.html.twig.
+ *
+ * Prepares the values passed to the theme_block function to be passed
+ * into a pluggable template engine. Uses block properties to generate a
+ * series of template file suggestions. If none are found, the default
+ * block.html.twig is used.
+ *
+ * Most themes use their own copy of block.html.twig. The default is located
+ * inside "core/modules/block/templates/block.html.twig". Look in there for the
+ * full list of available variables.
+ *
+ * @param array $variables
+ *   An associative array containing:
+ *   - elements: An associative array containing the properties of the element.
+ *     Properties used: #block, #configuration, #children, #plugin_id.
+ */
+
+//https://www.hashbangcode.com/article/drupal-9-programmatically-creating-and-using-urls-and-links
+
+function reha_preprocess_block(&$variables) {
+  if ($variables['plugin_id'] === "user_login_block") {
+    $url = new Url('user.register', [], ['query' => ['destination' => '/node/add/operation']]);
+    $link = new Link('proposer une operation', $url);
+    $variables['content']['reha'] = array(
+      '#theme' => 'item_list',
+      '#items' => [
+        'operations' => [
+          "add_operation" => $link->toRenderable(),
+          "description" => [
+            "#markup" => Markup::create("<p>Créer un compte pour charger une opération</p>")
+          ]
+        ]
+      ]
+    );
+  }
+}