Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • Hooks
  • Module
  • NodeLanguageElement
  • NodeNativeElement
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\I18n;
 13 
 14 use Icybee\Modules\Nodes\Node;
 15 use ICanBoogie\Event;
 16 use ICanBoogie\Modules;
 17 use Icybee\Modules\Nodes\PopNode;
 18 
 19 use Brickrouge\Element;
 20 use Brickrouge\Form;
 21 
 22 class Hooks
 23 {
 24     /**
 25      * Alters system.nodes module and submodules edit block with I18n options, allowing the user
 26      * to select a language for the node and a native source target.
 27      *
 28      * Only the native target selector is added if the `language` property is defined in the
 29      * HIDDENS array, indicating that the language is already set and cannot be modified by the
 30      * user.
 31      *
 32      * The I18n options are not added if the following conditions are met:
 33      *
 34      * - The working site has no native target
 35      * - The "i18n" module is disabled
 36      * - Only one language is used by all the sites available.
 37      * - The `language` property is defined in the CHILDREN array but is empty, indicating that
 38      * the language is irrelevant for the node.
 39      *
 40      * @param Event $event
 41      */
 42     static public function on_nodes_editblock_alter_children(Event $event, \Icybee\Modules\Nodes\EditBlock $block)
 43     {
 44         global $core;
 45 
 46         $site = $core->site;
 47 
 48         if (!$site->nativeid || !isset($core->modules['i18n']))
 49         {
 50             return;
 51         }
 52 
 53         $module = $event->module;
 54         $languages = $module->model->where('language != ""')->count('language');
 55 
 56         if (!count($languages)/* || current($languages) == $core->site->language*/)
 57         {
 58             return;
 59         }
 60 
 61         $children = &$event->children;
 62 
 63         if (array_key_exists(Node::LANGUAGE, $children) && !$children[Node::LANGUAGE])
 64         {
 65             return;
 66         }
 67 
 68         $event->attributes[Element::GROUPS]['i18n'] = array
 69         (
 70             'title' => 'i18n',
 71             'weight' => 100
 72         );
 73 
 74         if (!array_key_exists(Node::LANGUAGE, $event->attributes[Form::HIDDENS]))
 75         {
 76             $children[Node::LANGUAGE] = new NodeLanguageElement
 77             (
 78                 array
 79                 (
 80                     Element::GROUP => 'i18n',
 81                     'data-native-language' => $site->native->language,
 82                     'data-site-language' => $site->language
 83                 )
 84             );
 85         }
 86 
 87         $children[Node::NATIVEID] = new NodeNativeElement
 88         (
 89             array
 90             (
 91                 Element::GROUP => 'i18n',
 92                 NodeNativeElement::CONSTRUCTOR => $module->id
 93             )
 94         );
 95         /*
 96         $children[Node::NATIVEID] = new PopNode
 97         (
 98             array
 99             (
100                 Element::GROUP => 'i18n',
101                 PopNode::T_CONSTRUCTOR => $module->id
102             )
103         );
104         */
105     }
106 }
Autodoc API documentation generated by ApiGen 2.8.0