{"id":14634,"date":"2024-10-24T21:24:10","date_gmt":"2024-10-24T15:24:10","guid":{"rendered":"https:\/\/shra.ru\/?p=14634"},"modified":"2024-10-24T21:25:12","modified_gmt":"2024-10-24T15:25:12","slug":"obnovit-path-alias-v-taksonomii","status":"publish","type":"post","link":"https:\/\/shra.ru\/2024\/10\/obnovit-path-alias-v-taksonomii\/","title":{"rendered":"\u041e\u0431\u043d\u043e\u0432\u0438\u0442\u044c path alias \u0432 \u0442\u0430\u043a\u0441\u043e\u043d\u043e\u043c\u0438\u0438"},"content":{"rendered":"\n
\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 entityQuery \u0438 Entity API.<\/p>\n\n\n\n\n\n\n\n
\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u043f\u0440\u043e\u0439\u0434\u0435\u043c\u0441\u044f \u043f\u043e \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430\u043c \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0442\u0430\u043a\u0441\u043e\u043d\u043e\u043c\u0438\u0438 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0437\u0430\u043c\u0435\u043d\u0443 \u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u043e\u043d\u0438\u043c \u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u043c\u0443 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n\n\n\n
\u0412 8\u043a\u0435 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b (path_alias) — \u044d\u0442\u043e entity \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438 entityQuery \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u043d\u0438\u043c\u0438 \u043a\u0430\u043a \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 entity \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438.<\/p>\n\n\n\n
\u0417\u0430\u0434\u0430\u0447\u0430<\/strong>: \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \/blog\/ \u043d\u0430 \/perspectives\/ \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430\u0445, \u0430 \u0435\u0441\u043b\u0438 \u0441\u0438\u043d\u043e\u043d\u0438\u043c \u043d\u0435 \u0437\u0430\u0434\u0430\u043d, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443. \u0428\u0430\u0431\u043b\u043e\u043d\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432\u043e\u0442 \u0442\u0443\u0442 (\u044d\u0442\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043c\u043e\u0434\u0443\u043b\u0435\u043c pathauto): \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 entityQuery \u0438 Entity API.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[163],"acf":[],"yoast_head":"\n
\/admin\/config\/search\/path\/patterns<\/em><\/p>\n\n\n\n\/\/ \u041f\u043e\u043b\u0443\u0447\u0438\u043c ID \u0442\u0435\u0440\u043c\u0438\u043d\u043e\u0432 \u0438\u0437 \u0441\u043b\u043e\u0432\u0430\u0440\u044f blog_tags\n$tids = Drupal::entityQuery('taxonomy_term') \n ->condition('vid', 'blog_tags') \n ->accessCheck(FALSE) \n ->execute(); \n \nforeach ($tids as $tid) { \n \/\/ \u0414\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430 \u0438\u0449\u0435\u043c \u0430\u043b\u0438\u0430\u0441\n $path_ids = Drupal::entityQuery('path_alias') \n ->condition('path', '\/taxonomy\/term\/' . $tid) \n ->condition('alias', '\/blog\/', 'STARTS_WITH') \n ->accessCheck(FALSE) \n ->execute(); \n \n \/\/ \u0415\u0441\u043b\u0438 \u0441\u0438\u043d\u043e\u043d\u0438\u043c \u0435\u0441\u0442\u044c, \u0442\u043e \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u0442\u044c\n if ($path_ids) { \n $path = Drupal\\path_alias\\Entity\\PathAlias::load(array_pop($path_ids)); \n $path->setAlias(str_replace('\/blog\/', '\/perspectives\/', $path->getAlias())); \n $path->save(); \n } else { \n \/\/ \u0415\u0441\u043b\u0438 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u0430 \u043d\u0435\u0442, \u0442\u043e \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e\n \/\/ \u043f\u0435\u0440\u0435\u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0442\u0435\u0440\u043c\u0438\u043d\n $term = Drupal\\taxonomy\\Entity\\Term::load($tid); \n $term->save(); \n } \n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"