Drupal 8 – How do I programmatically delete a node using an internal URL alias?

After researching a little about the services available and the main classes, I have determined that you need to obtain the nid through path.alias_manager. In addition, you must wrap everything in a couple of conditions or it will throw errors if the route does not exist. (e.g., if you are trying to implement this change in a fleet of sites that may or may not have this route)

Below is my sample code:

  // Check the path is valid before proceeding.
  $pathIsValid = Drupal::pathValidator()->isValid('/blog');

  if ($pathIsValid) {
    $alias = Drupal::service('path.alias_manager')->getPathByAlias('/blog');
    $params = Url::fromUri("internal:" . $alias)->getRouteParameters();
    $entity_type = key($params);
    $nodeObj = Drupal::entityTypeManager()->getStorage($entity_type)->load($params($entity_type));

    // Get nid.
    $nid = $nodeObj->nid->value;
    $node = Node::load($nid);

    // Check if node exists with the given nid. Then 
    if ($node) {
      $node->delete();
    }
  }

Magento 2: where in the function of the permanent central url handle

where in core handle permanent URL function
where in core handle permanent URL function

Some help? Thanks in advance.

url – Help me get all the download links for this course!

Hello everyone,

I have enrolled in a language course at www.koreanclass101.com And they gave me a free 7-day trial. There are 15 lessons (each has 10-25 audios). Now I want to download / take all the links for the audio lessons of this site at once.

I used IDM grabber, entered the email and passed it and set it to download only audio files, but capture HTML pages instead of audio files.
Does anyone know how to use grabber on this site or at least one way to get all download links.

Would Google accept a text site map if the URL had a .php extension?

Google accepts a sitemap as a .txt file with a list of URLs each separated by a new line.

Would Google also allow the same text file format with a .php? That is to say.mysitemap.php instead of mysitemap.txt?

htaccess: redirect with URL path forwarding

I want to redirect from a subdomain to the domain along with the forwarding of the URL path.

Example:
abc.domain1.com/products.html

TO

domain2.com/products.html

The final URL must be retained.

We have more than 1000 subdomains created and some of them must be redirected to Domains. Subdomains are created virtually.

I am using the Linux and PHP web server as a language.

I think this can be done by changing the IP from domain2.com to domain1.com and adding some codes in the .htaccess file.

custom post types: create a short URL with 301 automatic redirect

I found this post (Create additional short URL with custom field and 301 redirect) and I tried to do this with a type of custom post I created but it doesn't work and I don't know what I'm doing wrong in this case. I have URL like this:

example.com/vacatures/junior-adviseur-kabels-en-leidingen-p565148-6/

and I want to create a short URL like this:

example.com/redirect/p565148-6/

And do a 301 redirect to

example.com/vacatures/junior-adviseur-kabels-en-leidingen-p565148-6/

I got a type of custom post called "Vacatures" and a custom field "vacature_id".

I already have this, but that does nothing.

add_action( 'init', 'vacature_rewrite_rule' );
function vacature_rewrite_rule() {
    add_rewrite_tag( '%vacature_id%', '((a-zA-Z0-9)+)' );
    add_rewrite_rule(
        '^redirect((a-zA-Z0-9)+)?',
        'index.php?vacature_id=$matches(1)',
        'top'
    );
}

add_action( 'parse_request', 'wpd_catch_vacature_requests' );
function wpd_catch_vacature_requests( $query ) {
    if( ! is_admin() && isset( $query->query_vars('vacature_id') ) ){
        $the_post = new WP_Query(
            array(
                'post_type' => 'vacatures',
                'meta_key'   => 'vacature_id',
                'meta_value' => $query->query_vars('vacature_id')
            )
        );
        if( $the_post->have_posts() ){
            wp_redirect( get_permalink( $the_post->post->ID ) );
        } else {
            wp_redirect( home_url() );
        }
    }
}

Create a custom view that passes a node ID in the url to print the node title

Battery exchange network

The Stack Exchange network consists of 175 question and answer communities, including Stack Overflow, the largest and most reliable online community for developers to learn, share their knowledge and develop their careers.

Visit Stack Exchange

Get the URL of the personalized publication of the connected user

I am running a multi-vendor WP site where users can create a business profile. The profile is a type of personalized publication (wyz-business).

I am looking to get the URL of the profile of the connected user (type of personalized publication).

When looking at the developer code, they seem to get the company’s URL from the user connected to


What I am trying to achieve is to create an insert link that users can put on their websites. Below is my functions.php code and then I insert the shortcode into the user panel, BUT it is returning the panel URL and not the user profile:

add_shortcode('embed-button', 'btn_embed');
function btn_embed(){
?>
Visit My Profile

What am I doing wrong?

This is the complete code and I am seeing the "title" class.

array( 'link' => WyzHelpers::add_clear_query_arg( array( WyzQueryVars::ManageBusiness => $curr_id ) ), 'label' => esc_html__( 'manage', 'wyzi-business-finder' ) ) ); if ( 'off' != get_option( 'wyz_users_can_booking' ) && WyzHelpers::wyz_sub_can_bus_owner_do( get_current_user_id() , 'wyzi_sub_business_can_create_bookings' ) ){ $business_tbl_btns('calendar') = array( 'link' => WyzHelpers::add_clear_query_arg( array( WyzQueryVars::BusinessCalendar => $curr_id ) ), 'label' => esc_html__( 'calendar', 'wyzi-business-finder' ) ); } $business_tbl_btns = apply_filters( 'wyz_published_business_table_buttons', $business_tbl_btns, $curr_id ); foreach ($business_tbl_btns as $key => $value) { echo '' . $value('label') . ''; }?>

URL rewriting: virtual page that uses URL parameters to solve Facebook sharing problems

Seeking help, my head is spinning! On my site, I have the ability to dynamically generate pages and use URL parameters to indicate the database and the registry to retrieve information to display, illustrations, etc.

The page that uses these parameters is a single page, but it has the potential to show thousands of different versions, depending on the records used.

The design is currently: domain.com/details/?ls=00A&ls2=00B

BUT Facebook, does not play ball when sharing such a definite page. Therefore, I need to turn this into a virtual page that is more of this design:

 domain.com/details/00A-00B/
 Where parameter 1 is 00A and parameter 2 is 00B

I think this has something to do with changing the rewrite rules or creating endpoints, but since the number of extensions outside the page called "details" can be thousands, that seems to cancel out the point of dynamically generated pages and the self maintenance

How would someone recommend achieving a wildcard extension effect?

      domain.com/details/*

It seems to be similar to this post:
Pass and read URL parameters with URL rewrite

However, that publication and other similar ones are more oriented to a "Fixed" extension and I am looking for a wildcard extension that can be read using a custom code (through a short code) on the Details page.

Other posts, like this one: Facebook sharer and URL parameters did not give a viable answer.

On Facebook, I have all the open graphics meta tags modified through Javascript, after the fact and I have confirmed the existence. It's just a matter of this virtual page using parameters as definition.

I need help.

TO UPDATE:
This is the last one and it still doesn't work. Requesting help:

 add_action( 'init', 'DetailsEndPointRules' );
 function DetailsEndPointRules( )
    {
    add_rewrite_tag("%ls%", '(d+)');                    //database record 
    add_rewrite_tag("%lid%", '(d+)');                   //List Id
    $tag   = '^details/(.+)/?$';    
    $regex = 'index.php?pagename=details&ls=$matches(1)&lid=$matches(2)';
    add_rewrite_rule($tag,$regex,'top');
    }

   // add the url parameters to the query variable list  
   add_filter( 'query_vars', 'DetailsParametersVariables' );
   function DetailsParametersVariables( $vars )
    {
    $vars() = 'ls';
    $vars() = 'lid';
    return $vars;
    }

NGINX: URL argument rewriting

I am trying and I cannot rewrite the following URL with nginx:

https: //mywebsite/myservice/pages/service/service.html? URL = / eServiceCNX / eservice.dll

to

https: //mywebsite/myservice/pages/service/service.html? URL = / eService / eservice.dll

I am basically trying to remove the "CNX" part of the "URL =" argument.

How can I do that ?

Thank you.