PHP code example of aplia / content-tools

1. Go to this page and download the library: Download aplia/content-tools library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aplia / content-tools example snippets



// Define the class, does not modify the database
$type = new Aplia\Content\ContentType('folder', 'Folder', array(
    'groups' => array('Content'),
    'isContainer' => true,
    'contentObjectName' => '<title>',
    'alwaysAvailable' => false,
    'description' => 'Container for other content objects',
    'sortBy' => 'name',
))
->addAttribute('ezstring', 'title', 'Title');

// Create the content-class in the database
$type->create();


$type->addAttribute('ezselection2', 'selection2', 'Selection 2', array(
    'value' => array(
        'delimiter' => '',
        'is_checkbox' => true,
        'is_multiselect' => true,
        'options' => array(
            ['identifier' => 'first', 'name' => 'First', 'is_selected' => false],
            ['identifier' => 'second', 'name' => 'Second', 'is_selected' => true],
            ['identifier' => 'third', 'name' => 'Third', 'is_selected' => false],
        ),
        'use_identifier_name_pattern' => true,
    )
));

ContentType::createGroup('Sections');

$type
    ->addToGroup('Sections')
    ->removeFromGroup('Content')
    ->save();

$type
    ->set(array(
        'groups' => array('Sections'),
    ));
    ->save();

$type
    ->addTranslation(
        'nor-NO',
        array(
            'name' => 'Seksjon',
            'description' => 'Seksjonssystem',
            'attributes' => array(
                'title' => array(
                    'name' => 'Tittel',
                )
            ),
        )
    )
    ->save();


$type->addAttribute('ezstring', 'title', 'Title', array(
    'value' => array(
        'max' => 50,
    )
))


$type->addAttribute('ezstring', 'title', 'Title', array(
    'value' => array(
        'max' => 50,
        'default' => 'Perfect Circle',
    )
))


$type->addAttribute('ezboolean', 'has_size', 'Has size?', array(
    'value' => array(
        'default' => true,
    )
))


$type->addAttribute('ezinteger', 'size', 'Size', array(
    'value' => array(
        'min' => 5,
        'max' => 10,
        'default' => 7,
    )
))


$type->addAttribute('eztext', 'body', 'Body', array(
    'value' => array(
        'columns' => 15,
    )
))


$type->addAttribute('ezxmltext', 'body', 'Body', array(
    'value' => array(
        'columns' => 15,
        'tag_preset' => 'whatever this is',
    )
))


$type->addAttribute('ezimage', 'image', 'Image', array(
    'value' => array(
        'max_file_size' => 10, // 10MB
    )
))


$type->addAttribute('ezimage', 'image', 'Image', array(
    'value' => array(
        'selection_type' => 1,
        'default_selection_node' => 2,
        'fuzzy_match' => false
    )
))


$type->addAttribute('ezurl', 'link', 'Link', array(
    'value' => array(
        'default' => 'http://example.com',
    )
))


// Create an object wrapper which is filled with data
$type = new Aplia\Content\ContentType('folder');
$folder = $type->contentObject(array(
    'locations' => array(array('parent_id' => 2)),
))
->setAttribute('title', 'New folder');

// Create the object in the database and publish it
$folder->create(true);


$object->setAttribute('body', new Aplia\Content\HtmlText('<p>My text</p>'));


$object->setAttribute('selection2', 'first|second')


$object->setAttribute('selection2', ['first', 'second'])


$object->setAttribute('image', new Aplia\Content\HttpFile('portrait_image'));

class Selection2Handler extends ContentBaseHandler implements ContentInputHandler
{
    public function storeContent($value)
    {
        $this->attribute->setAttribute('data_int', $value);
    }
}


iguration = new \Aplia\Migration\Configuration();
return $configuration->setupPhinx();
console
cat <export_name>.ndjson | sed -e '/ez_contentobject/,$d' > <export_name>.head; cat <export_name>.ndjson | sed -n -e '/ez_contentobject/,$p' | split -l5 - <export_name>- --additional-suffix=.tmp --numeric-suffixes=1; for f in <export_name>-*.tmp; do cat <export_name>.head "$f" > "${f%.*}".ndjson; rm "$f"; done
ini
TransformByUuid[c1426628bb809712ac78e8527ef93739]=FrontpageTransformation
ini
TransformByClass[user]=UserTransform
ini
Transform[]=GenericTransform
ini
[DataTypeSettings]
ContentInputHandler[ezselection2]=class;Selection2Handler
ini
[DataTypeSettings]
ContentInputHandler[ezselection2]=string
ini
[Migration]
Path=extension/mysite/migrations
ini
[Migration]
NamespacedPaths[Namespace\Path]=extension/mysite/migrations
console
php bin/dump_contentclass [identifier ...] [php-style] [preamble] [delete-existing] [update-class-group] [update-creator-id]
console
php vendor/aplia/content-tools/bin/dump_contentclass preamble delete-existing update-class-group=Seksjoner update-creator-id=14 news_section campaign_section logo_section > import_content_classes.php