Get all the text fields type and alter value after save

I’m trying to alter the value of entity text fields upon node save, even the custom-made fields

so far I’ve managed to do that with the title and default body field but not with a custom field, I’m trying to target any field that might be a text field, here’s my code:

function MODULENAME_entity_presave(Drupal\Core\Entity\EntityInterface $  entity) {   $  replacement_pattern = array("/a/", "/b/");    $  replacement = array("c", "d");    /* Check whether it's a node */   if ($  entity instanceof \Drupal\node\NodeInterface) {     // Node title     $  nodeTitle = $  entity->getTitle();     $  entity->setTitle(preg_replace($  replacement_pattern, $  replacement , $  nodeTitle));      // Body main     if(!empty($  entity->body->value)) {       $  entity->body->value = preg_replace($  replacement_pattern, $  replacement , $  entity->body->value);     }      // Body Summary     if(!empty($  entity->body->summary)) {       $  entity->body->summary = preg_replace($  replacement_pattern, $  replacement , $  entity->body->summary);     }   } } 

Solr query alter

I am working with search_api_solr and facet module in drupal 8 but while solr search from my site I am getting url is like this http://siteurl.local/products-filter-solr?f[0]=t:951 but as per requirement query would be http://siteurl.local/products-filter-solr?category=cat1&t=taxo1

I am searching the way to alter the solr query as per my requirement but not succeeded. Thanks in advance.

How to alter function so it won’t be on the one line but be curved using matplotlib? [on hold]

I have that code:

from matplotlib import pyplot as plt import numpy as np  halflife = 0.25 resolution_per_second = 1000 values = np.concatenate([np.zeros(resolution_per_second),                          np.ones(resolution_per_second * 2),                          np.zeros(resolution_per_second),                          np.ones(resolution_per_second * 1),                          np.zeros(resolution_per_second * 2),                          ]) t_grid = np.arange(0, len(values)) / resolution_per_second step = 1.0 / resolution_per_second k = np.power(0.5, 1 / (halflife * resolution_per_second))  def ema_fixed_step(y, k): #ema method 1 on chart     res = np.zeros_like(y)     curV = y[0]     for i in range(1, len(y) - 1):         curV = k * curV + (1 - k) * y[i]         res[i + 1] = curV     return res  ema1_arr = ema_fixed_step(values, k)  # w = values != np.roll(values, 1) w[0] = True t_new = t_grid[w] values_new = values[w] t_extra = [0.6, 1.0001, 1.2, 1.5, 2.9, 4.5, 3.3, 5.5]  t_req = np.sort(np.concatenate([t_new, t_extra]))   def ema_func2(t_req, t, y): #ema method 2 on chart     return np.zeros_like(t_req, dtype=np.double)  ema2_arr = ema_func2(t_req, t_new, values_new)  plt.clf() plt.step(t_grid, values, '.-', where='post', label='y') plt.step(t_grid, ema1_arr, '.-', where='post', label='ema method 1') plt.plot(t_req, ema2_arr, 'o', color='red', markersize=4, label='ema method 2')   plt.grid() plt.legend() plt.xlabel('t, seconds') 

That’s the part of code and that’s the result:

enter image description here

I need to complete ema_func2 so the dots would be on the orange line. How is it possible to complete function for those red dots appear on the orange curve. So, I need to take some piece from ema_fixed_step and somehow alter it according to t_req. How could it be done?

SQL stored proc hangs until i alter the proc

This is super weird and I don’t know where to start investigating. My web api project is throwing an error 500 when I try to call this specific stored proc in my db. I’m using SQL Server. The funny part is if I alter the script with no changes to it, just literally click alter and execute and nothing else, the error will go away. It seems like the sp is hanging during execution until I alter it and that somehow wipes out the blockage.

Any thoughts? Thanks!

How do I correctly implement hook_bootstrap_colorize_text() to alter button colors in a Bootstrap sub-theme?

I have read similar questions on here, but I’m still struggling for an answer for this.

I’m trying to implement hook_bootstrap_colorize_text() to alter button colors in a Bootstrap sub-theme.

I would like to add some specific text items to the array that dictates how the buttons are colorizes. For example, I have some buttons that have the “btn-default” class, and I would like to indicate specific texts to which should have “btn-success” or “btn-warning” instead.

The bootstrap.api.php describes this process:

/**  * Allows sub-themes to alter the array used for colorizing text.  * …  * @see _bootstrap_colorize_text()  */  function hook_bootstrap_colorize_text_alter(array &$  texts) {    // This matches the exact string: "My Unique Button Text".    $  texts['matches'][t('My Unique Button Text')] = 'primary';    // This would also match the string above, however the class returned would   // also be the one above; "matches" takes precedence over "contains".   $  texts['contains'][t('Unique')] = 'notice';    // Remove matching for strings that contain "apply":   unset($  texts['contains'][t('Apply')]);    // Change the class that matches "Rebuild" (originally "warning"):   $  texts['contains'][t('Rebuild')] = 'success'; } 

Therefore, I have attempted to implement the following code in my sub-theme (methodsTheme) template.php file without success.

<?php // Implements hook_bootstrap_colorize_text_alter() to alter button colors.   function methodstheme_bootstrap_colorize_text_alter(array &$  texts) {     $  texts['matches'][t('Request Rotation')] = 'success';     $  texts['contains'][t('Notify')] = 'success';     $  texts['contains'][t('Set')] = 'success';     $  texts['contains'][t('Mark')] = 'success';     $  texts['contains'][t('Assign')] = 'success';     $  texts['contains'][t('Report')] = 'warning';     $  texts['contains'][t('Request')] = 'info';   } ?> 

I’ve also tried:

<?php // Implements hook_bootstrap_colorize_text_alter() to alter button colors.   function methodstheme_bootstrap_colorize_text_alter(&$  texts) {     $  texts['matches'][t('Request Rotation')] = 'success';     $  texts['contains'][t('Notify')] = 'success';     $  texts['contains'][t('Set')] = 'success';     $  texts['contains'][t('Mark')] = 'success';     $  texts['contains'][t('Assign')] = 'success';     $  texts['contains'][t('Report')] = 'warning';     $  texts['contains'][t('Request')] = 'info';   } ?> 

And, I’ve also tried:

<?php // Implements hook_bootstrap_colorize_text_alter() to alter button colors.   function methodstheme_bootstrap_colorize_text_alter(&$  texts) {     $  texts = array(       'matches' => array(         t('Request Rotation') => 'success',       ),       'contains' => array(         t('Notify') => 'success',         t('Set') => 'success',         t('Mark') => 'success',         t('Assign') => 'success',         t('Report') => 'warning',         t('Request') => 'info',       ),     );   } ?> 

And, yes, after each attempt, I’m clearing the caches to see if the changes to the code are implemented to the desired result. However, I’m still emptyhanded. I’m placing the template.php file in my sites/all/themes/methodstheme/templates folder. The sub-theme was already established and working well (i.e., it is set-up properly, I believe).

I’m using Drupal 7.64 (with install profile varbase, but I’ve mostly removed all usage of the varbase profile and modules) and latest version of Bootstrap 3 theme as the base theme.

Can anyone offer some help or suggestions on what the issue may be?

Alter existing routes doesn’t work

I’m working on a D8 project trying to add custom access rules to some pages.

I want to restrict access to specific users based on their id.

I checked this and seems easy but I can’t make it work!

I want to change the access for the route

entity.webform_submission.canonical /admin/structure/webform/manage/{webform}/submission/{webform_submission}

But as I didn’t manage to make it work I tried an easier example

contact.site_page
/contact

(Which also doesn’t work)

So I created my routing file under my_module/src/Routing folder :

namespace Drupal\my_module\Routing;  use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\RouteCollection;  /**  * Listens to the dynamic route events.  */ class RouteSubscriber extends RouteSubscriberBase {    /**    * {@inheritdoc}    */   protected function alterRoutes(RouteCollection $  collection) {     if ($  route_item = $  collection->get('contact.site_page')) {       $  requirements = $  route_item->getRequirements();       unset($  requirements['_permission']);       $  route_item->setRequirement('_access', 'FALSE');     }   } } 

After that I added the service file in my_module’s root folder:

services:   my_module.route_subscriber:     class: Drupal\my_module\Routing\RouteSubscriber     tags:       - { name: event_subscriber } 

But I don’t get Access denied when I visit those pages.

Also, is there any way to test it by using dsm or var_dump?

Any idea/help/suggestion is valuable!

Thank you in advance.