add new object subtype pages

Hello, i like add new object of plugin pages for a group.this is correct??

the group guid are 857

$object = new ElggObject();
$object->subtype = 'page_top';
$object->description = 'lore ipsum';
$object->container_guid = '857';




  • you can either delete it and create a new one, or just fix by assigning an owner and container

  • Pages stores the content in annotations in order to store revisions and the views display the annotation values.

  • steve

    is true in the annotations is not the page.

    restore the installation I have no problem, thanks to rodolfo make backups;)

    the problem as I have in the code, i dont know I'm writing.

    what is owner_guid?
    and container_guid?

    if i put container_guid = 127 fatal mistake me


    thanks to everybody, i m desperate.

  • i investigate the page plugin and i founda new.php


    * Create a new page
    * @package ElggPages


    $container_guid = (int) get_input('guid');  
    $container = get_entity($container_guid);
    if (!$container) {


    $parent_guid = 0;
    $page_owner = $container;
    if (elgg_instanceof($container, 'object')) {
    $parent_guid = $container->getGUID();
    $page_owner = $container->getContainerEntity();


    $title = elgg_echo('pages:add');

    $vars = pages_prepare_form_vars(null, $parent_guid);
    $content = elgg_view_form('pages/edit', array(), $vars);

    $body = elgg_view_layout('content', array(
    'filter' => '',
    'content' => $content,
    'title' => $title,

    echo elgg_view_page($title, $body);


  • You need to delete entities you created with owner_guid = 0. Cash's DB validator may help here, or you can just delete the problem entity in the Elgg entities table.

  • thanks steve, but this is not the problem, i have backup of db, i try to make a plugin to export pages to other groups and i like create code for create one page_top.



    sorry for my english!!!

  • The pages/edit action has the code that creates pages, though it's a little confusing because it also handles saving existing ones. But if you consider $page_guid will be 0, you can more clearly see what will run.

  • its ok!!! very thanks!!this is the code:

            $page_guid = 0;
            $parent_guid = 0;
            /////////creacion de la pagina nueva ////////////////////
           $variables = elgg_get_config('pages');
           $page = new ElggObject();
           $page->description = $descripcion;
           $page->subtype = $subtipo;
           $page->title = $titulo;
           $page->description = $descripcion;
           $new_page = true;
           // need to add check to make sure user can write to container
            $page->container_guid = $container_guid;
            if ($parent_guid) {
                $page->parent_guid = $parent_guid;
            if ($page->save()) {
                // Now save description as an annotation
                $page->annotate('page', $descripcion, $page->access_id);
                // Fin SubPaginasTopLectura
            /////////Fin creacion de la pagina nueva ////////////////////

    And this a funcion subpaginas (subpages)

    function funcionsubpaginas($pagelectura,$guidescritura){
    $subPaginas = elgg_get_entities_from_metadata(array('metadata_names' => 'parent_guid',
                                                        'metadata_values' =>$pagelectura->getGUID(),
                                                        'limit' => 9999));
    $guidhere = $guidescritura; //pagina destino
    foreach ($subPaginas as $name2) {
        //-Crea subpagina
        $page = new ElggObject();
        $page->subtype = 'page';
        $page->title = $name2->title;
        $page->description = $name2->description;
        $page->parent_guid = $guidhere;
        $page->container_guid = $guidhere; //grupo destino pasar mas tarde como parametro.
        // Now save description as an annotation
        $page->annotate('page', $page->description, $page->access_id);
        $subPaginas2 = elgg_get_entities_from_metadata(array('metadata_names' => 'parent_guid',
                                                             'metadata_values' =>$name2->getGUID(),
                                                             'limit' => 9999));

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking