Yosymfony\Spress\Core\ContentManager\Permalink\PermalinkGenerator::getPermalink PHP Method

    public function getPermalink(ItemInterface $item)
    {
        if ($item->getPath(ItemInterface::SNAPSHOT_PATH_RELATIVE_AFTER_CONVERT) === '') {
            return new Permalink('', '');
        }
        $placeholders = $this->getPlacehoders($item);
        $permalinkStyle = $this->getPermalinkAttribute($item);
        $noHtmlExtension = $this->getNoHtmlExtensionAttribute($item);
        if ($item->isBinary() === true) {
            $urlTemplate = $this::PERMALINK_NONE;
            $path = $this->generatePath($urlTemplate, $placeholders);
            $urlPath = $this->generateUrlPath($urlTemplate, $placeholders);
            return new Permalink($path, $urlPath);
        }
        switch ($permalinkStyle) {
            case 'none':
                $urlTemplate = $this::PERMALINK_NONE;
                break;
            case 'ordinal':
                if ($this->isItemWithDate($item) === true) {
                    $urlTemplate = $this::PERMALINK_ORDINAL;
                    if ($this->isCustomCollection($item)) {
                        $urlTemplate = '/:collection' . $urlTemplate;
                    }
                } else {
                    $urlTemplate = $this::PERMALINK_NONE;
                }
                break;
            case 'pretty':
                $noHtmlExtension = true;
            case 'date':
                if ($this->isItemWithDate($item) === true) {
                    $urlTemplate = $this::PERMALINK_DATE;
                    if ($this->isCustomCollection($item)) {
                        $urlTemplate = '/:collection' . $urlTemplate;
                    }
                } else {
                    $urlTemplate = $this::PERMALINK_NONE;
                }
                break;
            default:
                if ($this->templateNeedsDate($permalinkStyle) === false || $this->isItemWithDate($item) === true) {
                    $urlTemplate = $permalinkStyle;
                } else {
                    $urlTemplate = $this::PERMALINK_NONE;
                }
                break;
        }
        if ($noHtmlExtension && $placeholders[':extension'] === 'html') {
            if ($placeholders[':basename'] === 'index') {
                $placeholders[':basename'] = '';
            }
            $urlTemplate = str_replace(['.:extension', ':extension'], '', $urlTemplate);
            $pathTemplate = $urlTemplate . '/index.html';
        } else {
            $pathTemplate = $urlTemplate;
        }
        $path = $this->generatePath($pathTemplate, $placeholders);
        $urlPath = $this->generateUrlPath($urlTemplate, $placeholders);
        return new Permalink($path, $urlPath);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * @expectedException \Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException
  */
 public function testPrettyBadDateAttribute()
 {
     $pmg = new PermalinkGenerator('pretty');
     $permalink = $pmg->getPermalink($this->createItem('index.html', ['date' => []]));
 }
All Usage Examples Of Yosymfony\Spress\Core\ContentManager\Permalink\PermalinkGenerator::getPermalink