forms – If I have 2 same name taxonomy term which is used with nodes. how to set only one instead of both?

I have 2 taxonomy terms with the same name (knight(2) and knight(6)) in my Drupal 8 Project; both terms have been used with nodes.

I want to replace knight(6) with knight(2) in all the nodes. I created the following custom form.

screenshot

The submission handler code is the following one.

  public function submitForm(array &$form, FormStateInterface $form_state) {
  
  $values =  $form_state->getValues();
  $old_term = $values('old_taxonomy_term');
  $new_term = $values('new_taxonomy_term');
  $query = Drupal::entityQuery('node')
    ->condition('type','a')
    ->condition('field_taxonomy_', $old_term, '=');
  $results = $query->execute();

  foreach ($results as $nid) {
    $node = DrupalnodeEntityNode::load($nid);
    $abc = $node->get('field_taxonomy_')->referencedEntities(); 
    foreach ($abc as $key => $value) {
      $value = reset($value);
      if ($key('tid') == $old_term) {
        $node->set('field_taxonomy_',$new_term);
        $node->save();
      }
    }
  }   
}

The code doesn’t work.

nodes – How to apply filtration upon 2 same name taxonomy terms. for set original term instead of duplicate term?

I have 2 taxonomy terms with the same name (knight(2) and knight(6)) in my Drupal 8 Project. I used both terms with nodes. Now I want to override knight(6) with knight(2) in all the nodes. I applied my logic, but it isn’t working. Please suggest any correct solution.

I have a form that asks for the taxonomy term to replace and the taxonomy term that replace it. Clicking on the submission button should replace the old taxonomy term with the new one.

screenshot

How to prefix custom post type URL with custom post taxonomy term?

For one of my CPT, when default permalink looks like
example.com/CPT_slug/%postname%

instead I would like a permalink like this :
example.com/%custom_taxonomy_term%/CPT_slug/%postname%

With regular categories and posts, it’s easy to do, I just have to use %category%/%postname% for permalinks.

But I can’t for the life of me achieve it for CPT and custom taxonomies. What am I doing wrong ?

My CPT slug is “activity”, with posts like : “Food tour”, “Dinner cruise”, …
My Custom Taxonomy slug is “agence”, with terms like “New York”, “Miami”, …

So I’d like my URLs to be like

(where, ideally, in case of “same slug” situations, disambiguation would be dealt with)

I’ve tried this approach :

"rewrite" => array( "slug" => "%agence%/activity", "with_front" => false ),

in register_post_type

and

function add_agence_prefix_in_activity_url( $post_link, $id = 0 ) {
    $post = get_post( $id );
    if ( is_object( $post ) && get_post_type($post) == 'activity' )
    {
        $terms = wp_get_object_terms( $post->ID, 'agence' );
        if ( $terms ) {
            return str_replace( '%agence%', $terms(0)->slug, $post_link );
        }
    }

    return $post_link;
}
add_filter( 'post_type_link', 'add_agence_prefix_in_activity_url', 1, 3 );

It works : it lets me display my “activity” post content.
But I get 404 errors when trying to display posts & pages with their usual /%postname% permalinks; and I don’t know what to do to fix this.

So instead I tried using the plugin “Custom Post Type Permalinks” :
it almost works : pages & posts are not broken anymore, and it gives me URLs like
https://www.example.com/activity/**new-york**/food-tour
… whereas I would like
https://www.example.com/**new-york**/activity/food-tour

So i’m almost there, but not quite.
How should I proceed ? Is what I am trying to do even possible ?

forms – How do I get the term name in a custom submit handler?

In Drupal 8/9, when you create a new term, the default status message is:

Created new term %term.

%term contains the term name, which is linked to the term page.

I want to override this and remove the link (I want to show the term name, but I do not want to link the term name to the term page).

I thought I could do this in a custom submit handler:

function MYMODULE_term_create_form_submit(array &$form, FormStateInterface &$form_state) {
  Drupal::messenger()->deleteByType('status');
  Drupal::messenger()->addMessage(t('The group @group-name has been added.', ('@group-name' => NULL)));
}

However, I don’t know how to get the term’s name from $form. I searched the $form object with kint() and I could not find the form name.

Then I looked at core, which does this:

  public function save(array $form, FormStateInterface $form_state) {
    $term = $this->entity;

    $result = $term->save();

    $edit_link = $term->toLink($this->t('Edit'), 'edit-form')->toString();
    $view_link = $term->toLink()->toString();
    switch ($result) {
      case SAVED_NEW:
        $this->messenger()->addStatus($this->t('Created new term %term.', ('%term' => $view_link)));
        $this->logger('taxonomy')->notice('Created new term %term.', ('%term' => $term->getName(), 'link' => $edit_link));
        break;

But, I don’t have access to the term object in the submit handler.

What’s the simplest way to do this without doing a quick-and-dirty patch to core?

website – What is actually meant by the term ‘stock browser’ in web development?

I’m a Web Developer by profession.

Today I come across the new term ‘stock browser’ which I’ve never heard before in my 10 years of web development experience.

The text around the term ‘stock browser’ is as below :

A shim differs from a polyfill, which implements a new API that is not
supported by the stock browser as shipped.

From the above statement I didn’t get at all the meaning and context of using the term ‘stock browser’.

Can someone experienced from Web Developer community explain the meaning of the term ‘stock browser’ with proper context to me?

Thank You.

Note : If you want I can provide you the link from where I got the quoted text.

website – What does actually mean by the term ‘stock browser’ in web development?

I’m a Web Developer by profession.

Today I come across the new term ‘stock browser’ which I’ve never heard before in my 10 years of web development experience.

The text around the term ‘stock browser’ is as below :

A shim differs from a polyfill, which implements a new API that is not
supported by the stock browser as shipped.

From the above statement I didn’t get at all the meaning and context of using the term ‘stock browser’.

Can someone experienced from Web Developer community explain the meaning of the term ‘stock browser’ with proper context to me?

Thank You.

Note : If you want I can provide you the link from where I got the quoted text.

Creating Archive Page – All Posts with Any Term of Custom Taxonomy

Is there any standard way within WordPress to create an archive page for a given taxonomy (one that will output all posts which have any term from that taxonomy)

There’s a few ways to accomplish this goal:

  1. Using the save_post hook, every time a post-type with the taxonomy is saved we could test to see if terms from the taxonomy are in use and add/remove a post_meta flag, then query by that for our archive page.

  2. We could also maintain a transient variable containing the id’s of all the posts with any term of the custom taxonomy then add a post__in argument to the query.

  3. We could retrieve all the terms of the custom taxonomy & add a custom tax_query

And a handful of other ways, but is there anything simpler i might be missing?

Get the form to add a term to a vocabulary programmatically

I am working on Drupal 8.9.6.

I am trying to retrieve the form to add a term to a vocabulary programmatically. I know how to do it for a content type:

    $values = array('type' => $content_type);

    $node = Drupal::entityTypeManager()
      ->getStorage('node')
      ->create($values);

    $form = Drupal::entityTypeManager()
      ->getFormObject('node', 'default')
      ->setEntity($node);
    $modal_form =  Drupal::formBuilder()->getForm($form);

Nevertheless, I am not able to do the same for the form of adding a term to a vocabulary. Any hint would be more than welcome.

Thanks!

data – Artificial Neural Networks For Long Term Time Series Predictions

I have developed a ANNs model to make time series predictions, I was successful in developing an algo for ‘one-step ahead’ predictions (e.g., using data of today datapoint to make tomorrow’s prediction datapoint).

Now, I would like to make a more long term prediction (e.g., next week datapoints predictions, or next month datapoints predictions).

Would anyone advise a good source/paper/tutorial for this?

Thank you!