By admin , 1 March, 2023 Input preprocess /** * Implements template_preprocess_input(). */ function EXAMPLE_preprocess_input(&$variables) { if (isset($variables['attributes']['id'])) { if ($variables['attributes'][ Tags preprocess input
By admin , 1 March, 2023 Fieldset preprocess /** * Implements template_preprocess_fieldset() */ function EXAMPLE_preprocess_fieldset(&$variables) { if (isset($variables['element']['#id'])) { $id = $variables['element']['#id'] Tags preprocess fieldset
By admin , 1 March, 2023 Redirect user if view page /** * Implements hook_preprocess_HOOK(). */ function EXAMPLE_preprocess_page(&$variables) { $route_name = \Drupal::routeMatch()->getRouteName(); if ($route_name == 'entity.user.canonical') { $current_user = \Drupal::currentUser(); $roles = $current_user->getRoles(); if Tags routes redirect
By admin , 28 February, 2023 Remove nodes of type "product" $nodes = $this->entityTypeManager->getStorage('node')->loadByProperties([ 'type' => 'product', ]); foreach ($nodes as $node) { $node->delete(); } Tags node entityTypeManager
By admin , 28 February, 2023 Run batch from form /** * Import categories batch. */ public static function importCategories($arg1, $arg2, &$context) { $a = 1; } /** * {@inheritdoc} */ public Tags form batch
By admin , 28 February, 2023 Download files from array of links, create File entities and attach them to node $files = []; $index = 1; foreach ($pictures as $picture) { $filename = 'image_' . $offer_id . '_' . $index . '.jpg'; $destination = 'sites/default/files/product-photos/' . Tags node file guzzle
By admin , 28 February, 2023 Create node programmatically $node = Node::create([ 'type' => 'product', 'title' => $offer_name, 'add_to_cart_price' => $offer_price, 'field_offer_id' => $offer_id, 'body' => $offer_desc . Tags node
By admin , 28 February, 2023 Get taxonomy term by propetries $category_term = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties([ 'vid' => 'category', 'field_category_id' => $id, ]); $category_term = \reset($category_term); Tags entityTypeManager taxonomy
By admin , 28 February, 2023 Form for file import /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $validators = [ 'file_validate_extensions' => ['xml'], ]; $form['upload'] = [ '#type' Tags import form
By admin , 24 February, 2023 Inject messenger use Drupal\Core\Messenger\MessengerInterface; /** * The messenger service. * * @var \Drupal\Core\Messenger\MessengerInterface */ protected $messenger; /** * The form constructor. * * @param \Drupal\Core\Messenger\MessengerInterfa Tags dependency injection messenger