Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/brizy-pro   php

Repository URL to install this package:

Version: 2.3.7 

/ placeholders / post-loop-tags.php

<?php
use BrizyPlaceholders\ContentPlaceholder;
use BrizyPlaceholders\ContextInterface;

class BrizyPro_Content_Placeholders_PostLoopTags extends Brizy_Content_Placeholders_Abstract {


	/**
	 * BrizyPro_Content_Placeholders_PostLoopPagination constructor.
	 * @throws Exception
	 */
	public function __construct() {
		$this->placeholder = 'brizy_dc_post_loop_tags';
		$this->label       = 'Post loop tags';
		$this->setDisplay( self::DISPLAY_BLOCK );
        $this->setGroup(null);
	}


    /**
     * @param ContextInterface $context
     * @param ContentPlaceholder $contentPlaceholder
     * @return false|mixed|string
     */
    public function getValue( ContextInterface $context, ContentPlaceholder $contentPlaceholder ) {

		$attributes = $contentPlaceholder->getAttributes();

		$tagsContext              = array();
		$tagsContext['tags']      = $this->getTagList( $attributes );
		$tagsContext['ulClassName'] = isset( $attributes['ulClassName'] ) ? $attributes['ulClassName'] : '';
		$tagsContext['liClassName'] = isset( $attributes['liClassName'] ) ? $attributes['liClassName'] : '';

        if (isset($attributes['content_type']) && $attributes['content_type'] === 'json') {
            return json_encode($this->getTagList( $attributes ));
        }

		return Brizy_TwigEngine::instance( BRIZY_PRO_PLUGIN_PATH . "/content/views/" )->render( 'tags.html.twig', $tagsContext );
	}

	protected function getTagList( $args ) {
		$tax   = isset( $args['tax'] ) ? $args['tax'] : 'post_tag';
		$terms = get_terms( [ 'taxonomy' => $tax, 'hide_empty' => true ] );

		if ( is_wp_error( $terms ) ) {
			return [];
		}

		return $terms;
	}
}