Airship\Cabin\Bridge\Blueprint\CustomPages::createPageRedirect PHP Méthode

createPageRedirect() public méthode

Create a page redirect
public createPageRedirect ( array $old, array $new, boolean $allowCrossCabin = false ) : boolean
$old array
$new array
$allowCrossCabin boolean
Résultat boolean
    public function createPageRedirect(array $old, array $new, bool $allowCrossCabin = false) : bool
    {
        if (!$allowCrossCabin && $old['cabin'] !== $new['cabin']) {
            return false;
        }
        $cabin = $old['cabin'];
        $oldPath = !empty($old['directory']) ? $this->getPathFromDirectoryId((int) $old['directory'], $cabin) : [];
        $oldPath[] = $old['url'];
        $oldURL = \implode('/', $oldPath);
        $newPath = !empty($new['directory']) ? $this->getPathFromDirectoryId((int) $new['directory'], $cabin) : [];
        $newPath[] = $new['url'];
        $newURL = \implode('/', $newPath);
        if ($oldURL === $newURL) {
            return false;
        }
        return $this->createSameCabinRedirect($oldURL, $newURL, $cabin);
    }

Usage Example

Exemple #1
0
 /**
  * Move a page
  *
  * @param array $page
  * @param array $post
  * @param string $cabin
  * @param string $dir
  * @return bool
  */
 protected function processMovePage(array $page, array $post, string $cabin, string $dir) : bool
 {
     if (\is_numeric($post['directory'])) {
         $post['cabin'] = $this->pg->getCabinForDirectory($post['directory']);
     } elseif (\is_string($post['directory'])) {
         // We're setting this to the root directory of a cabin
         $post['cabin'] = $post['directory'];
         $post['directory'] = 0;
     } else {
         // Invalid input.
         return false;
     }
     // Actually process the new page:
     if ($page['directory'] !== $post['directory'] || $page['cabin'] !== $post['cabin'] || $page['url'] !== $post['url']) {
         $this->pg->movePage((int) $page['pageid'], $post['url'], (int) $post['directory']);
         if (!empty($post['create_redirect'])) {
             $this->pg->createPageRedirect(\Airship\keySlice($page, ['cabin', 'directory', 'url']), \Airship\keySlice($post, ['cabin', 'directory', 'url']));
         }
         \Airship\redirect($this->airship_cabin_prefix . '/pages/' . $cabin, ['dir' => $dir]);
     }
     return false;
 }