Bolt\Legacy\Content::__construct PHP Method

__construct() public method

public __construct ( Silex\Application $app, string $contenttype = '', array $values = [], boolean $isRootType = true )
$app Silex\Application
$contenttype string
$values array
$isRootType boolean
    public function __construct(Silex\Application $app, $contenttype = '', $values = [], $isRootType = true)
    {
        $this->app = $app;
        $this->isRootType = $isRootType;
        if (!empty($contenttype)) {
            // Set the contenttype
            $this->setContenttype($contenttype);
            // If this contenttype has a taxonomy with 'grouping', initialize the group.
            if (isset($this->contenttype['taxonomy'])) {
                foreach ($this->contenttype['taxonomy'] as $taxonomytype) {
                    if ($this->app['config']->get('taxonomy/' . $taxonomytype . '/behaves_like') == 'grouping') {
                        $this->setGroup('', '', $taxonomytype);
                    }
                    // add support for taxonomy default value when options is set
                    $defaultValue = $this->app['config']->get('taxonomy/' . $taxonomytype . '/default');
                    $options = $this->app['config']->get('taxonomy/' . $taxonomytype . '/options');
                    if (isset($options) && isset($defaultValue) && array_search($defaultValue, array_keys($options)) !== false) {
                        $this->setTaxonomy($taxonomytype, $defaultValue);
                        $this->sortTaxonomy();
                    }
                }
            }
        }
        $this->user = $this->app['users']->getCurrentUser();
        if (!empty($values)) {
            $this->setValues($values);
        } else {
            // Ininitialize fields with empty values.
            if (is_array($this->contenttype) && is_array($this->contenttype['fields'])) {
                foreach ($this->contenttype['fields'] as $key => $parameters) {
                    // Set the default values.
                    if (isset($parameters['default'])) {
                        $values[$key] = $parameters['default'];
                    } else {
                        $values[$key] = '';
                    }
                }
            }
            if (!empty($this->contenttype['singular_name'])) {
                $contenttypename = $this->contenttype['singular_name'];
            } else {
                $contenttypename = "unknown";
            }
            // Specify an '(undefined contenttype)'.
            $values['name'] = "(undefined {$contenttypename})";
            $values['title'] = "(undefined {$contenttypename})";
            $this->setValues($values);
        }
    }