Wednesday 26 August 2020

How to remove or unset url links form simple sitemap in druapl 8?

Simple way to unset the URL link is alter simple sitemap module, here we will give an example of code for remove or unset any link on any condition basis.

Example:

Create a custom module or put the code in existing custom module.

a. First render class library in file header.

use Drupal\simple_sitemap\Simplesitemap;

b. Then write the hook function code.

/**

 * Alter the generated link data before the sitemap is saved.

 * This hook gets invoked for every sitemap chunk generated.

 *

 * @param array &$links

 *   Array containing multilingual links generated for each path to be indexed.

 */

function finder_simple_sitemap_links_alter(&$links) {


  // Remove french URL for a certain path in the hreflang sitemap.

  foreach ($links as $key => $link) {

    if ($link['path'] === 'node/1') {

      // Remove 'loc' URL if it points to a french site.

      if ($link['langcode'] === 'fr') {

        unset($links[$key]);

      }

      // If this 'loc' URL points to a non-french site, make sure to remove

      // its french alternate URL.

      else {

        if ($link['alternate_urls']['fr']) {

          unset($links[$key]['alternate_urls']['fr']);

        }

      }

    }

  }

}


Note: If have any suggestions or issue regarding 'How to remove or unset url links form simple sitemap in druapl 8?' then you can ask by comments. 

Tuesday 25 August 2020

How to alter or add custom url links in simple sitemap in drupal 8?

 It is very simple method, we have 2 options in Drupal 8.

https://www.drupal.org/project/simple_sitemap

1. we can add by config page of module like (//localhost//admin/config/search/simplesitemap/custom). There add custom links with priority with change frequency.

2. we can use alter method with simple steps::

a. Create any custom module or write code in any existing custom module.

b. go to custom_module.module file or create new if not exist.

c. write code line with below given example:

Example:

First render class library in file header.

use Drupal\simple_sitemap\Simplesitemap;

/**

 * Use this hook to add arbitrary links to the sitemap.

 *

 * @param array &$arbitrary_links

 */

function finder_simple_sitemap_arbitrary_links_alter(&$arbitrary_links) {


  // Add an arbitrary link.

  $arbitrary_links = array([

    'url' => 'https://localhost/applications',

    'priority' => '0.9',

    'lastmod' => '2020-05-25T14:40:30+02:00',

    'changefreq' => 'daily',

],

[

'url' => 'https://localhost/products',

    'priority' => '0.7',

    'lastmod' => '2020-07-15T13:40:30+02:00',

    'changefreq' => 'daily',

    ],

);

}

Note: We can't add date(lastmod) in custom links by admin, so we have to use alter code for add dates(lastmod) in custom create links.


Note: If have any suggestions or issue regarding 'How to alter or add custom url links in simple sitemap in drupal 8?' then you can ask by comments. 

Wednesday 5 August 2020

How to remove HTTP headers from drupal 8?

Sometimes client requirement is to remove HTTP headers from the website. By default, in Drupal website X-Generator, X-Drupal-Dynamic-Cache and X-Drupal-Cache HTTP headers is HTTP headers.
If we want to hide to remove from view source of page.
We can use Drupal module "Remove HTTP headers"
That will remove easily… 
headers_to_remove:
  - 'X-Generator' 
  - 'X-Drupal-Dynamic-Cache'
  - 'X-Drupal-Cache'
  
Important Note: if you get any issue/error, you can use this patch.

1. Go to your module and find folder route file - src/EventSubscriber/RemoveResponseHeadersSubscriber.php
2. find this function -
class RemoveResponseHeadersSubscriber implements EventSubscriberInterface {
    
   public function removeResponseHeadersItem(FilterResponseEvent $event) {
     $response = $event->getResponse();
+    $config = $this->configFactory->get('remove_meta_and_headers.settings');
 
     // If TRUE, fire event to remove X-Generator from Response.
-    if (1 == $this->configFactory->get('response_header_x_generator')) {
+    if ($config->get('response_header_x_generator')) {
       $response->headers->remove('X-Generator');
     }
   }

OR check this patch link…

   

Note: If have any suggestions or issue regarding 'How to remove HTTP headers from drupal 8?' then you can ask by comments. 

How to resolve max execution time error in drupal ?

When you found error regarding 'max_execution_time' exceed, then you can follow steps for resolve this error: Steps:   You can put t...