<commit_before><?php
namespace Craft;

/**
 * FFFields
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017, <NAME> Ltd
 * @see       https://angell.io/plugins/fffields
 * @since     1.0
 */
class FffieldsService extends BaseApplicationComponent
{
    // Properties
    // =========================================================================

    /**
     * The original template path.
     *
     * @var string
     */
    protected $oldPath;

    /**
     * Our plugin template path.
     *
     * @var string
     */
    protected $newPath;

    // Public Methods
    // =========================================================================

    /**
     * Set the template path to our plugin one
     */
    public function __construct()
    {
        $this->oldPath = craft()->templates->getTemplatesPath();
        $this->newPath = craft()->path->getPluginsPath().'fffields/templates';
        craft()->templates->setTemplatesPath($this->newPath);
    }

    /**
     * Reset the parent path when the class gets killed
     */
    public function __destruct()
    {
        craft()->templates->setTemplatesPath($this->oldPath);
    }

    /**
     * Renders the field layout for a given element and optional field layout.
     *
     * @param BaseElementModel      $element
     * @param FieldLayoutModel|null $fieldLayout
     *
     * @return bool|\Twig_Markup
     */
    public function render(BaseElementModel $element, FieldLayoutModel $fieldLayout = null)
    {

        if (!$fieldLayout) {

            $elementType = craft()->elements->getElementTypeById($element->id);

            if (!$elementType) {
                return false;
            }

            switch ($elementType) {
                case 'Entry' :
                    $fieldLayout = $element->getType()->getFieldLayout();
                    break;
            }

        }

        if (!$fieldLayout) {
            return false;
        }

        $html = craft()->templates->render('fieldlayout', [
            'element' => $element,
            'fieldLayout' => $fieldLayout
        ]);

        return TemplateHelper::getRaw($html);
    }

    /**
     * Renders the markup for a specific field.
     *
     * @param array $params
     *
     * @return bool|\Twig_Markup
     */
    public function renderField(array $params)
    {

        if (!isset($params['element'], $params['fieldLayoutField'], $params['namespace'])) {
            return false;
        }

        $element = $params['element'];<commit_msg>Fixed issue with template path not being reset after it was changed.<commit_after><?php
namespace Craft;

/**
 * FFFields
 *
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (c) 2017, <NAME> Ltd
 * @see       https://angell.io/plugins/fffields
 * @since     1.0
 */
class FffieldsService extends BaseApplicationComponent
{

    // Public Methods
    // =========================================================================

    /**
     * Renders the field layout for a given element and optional field layout.
     *
     * @param BaseElementModel      $element
     * @param FieldLayoutModel|null $fieldLayout
     *
     * @return bool|\Twig_Markup
     */
    public function render(BaseElementModel $element, FieldLayoutModel $fieldLayout = null)
    {

        if (!$fieldLayout) {

            $elementType = craft()->elements->getElementTypeById($element->id);

            if (!$elementType) {
                return false;
            }

            switch ($elementType) {
                case 'Entry' :
                    $fieldLayout = $element->getType()->getFieldLayout();
                    break;
            }

        }

        if (!$fieldLayout) {
            return false;
        }

        $oldPath = craft()->templates->getTemplatesPath();
        $newPath = craft()->path->getPluginsPath().'fffields/templates';
        craft()->templates->setTemplatesPath($newPath);

        $html = craft()->templates->render('fieldlayout', [
            'element' => $element,
            'fieldLayout' => $fieldLayout
        ]);

        craft()->templates->setTemplatesPath($oldPath);

        return TemplateHelper::getRaw($html);
    }

    /**
     * Renders the markup for a specific field.
     *
     * @param array $params
     *
     * @return bool|\Twig_Markup
     */
    public function renderField(array $params)
    {

        if (!isset($params['element'], $params['fieldLayoutField'], $params['namespace'])) {
            return false;
        }

        $element = $params['element'];
{'fraction_non_alphanumeric': 0.17442882249560632, 'fraction_numerical': 0.0026362038664323375, 'mean_word_length': 2.0972789115646258, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6173778', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1157, 'n_words': 264}