Skip to content

Instantly share code, notes, and snippets.

@arfaram
Last active July 14, 2019 17:06
Show Gist options
  • Save arfaram/3f38e7a818b328075ed0ff85d57f3ea0 to your computer and use it in GitHub Desktop.
Save arfaram/3f38e7a818b328075ed0ff85d57f3ea0 to your computer and use it in GitHub Desktop.

Set right Permission:

//Best Practice user ID in parameters.yml 
//@deprecated since 6.6 to be removed:
//$repository->setCurrentUser($repository->getUserService()->loadUserByLogin( 'admin' ));
//$repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
Use now:
$repository->getPermissionResolver()->setCurrentUserReference( $repository->getUserService()->loadUser( 14 ) );

setField():

ezstring

$contentCreateStruct->setField('title', 'text');  

ezimage

$contentCreateStruct->setField('photo', '/data/image.jpg');

or

      $value = new \eZ\Publish\Core\FieldType\Image\Value(
          array(
              'path' => $file,
              'fileSize' => filesize( $file ),
              'fileName' => basename( $file ),
              'alternativeText' => $name
          )
      );
      $contentCreateStruct->setField( 'image', $value );

ezrichtext

$body = '<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><para>'.utf8_encode(trim($data)).'</para></section>';

ezgmaplocation

$contentCreateStruct->setField('starting_point',array(
        'address' => $address,
        'latitude' => (float) $latitude,
        'longitude' => (float) $longitude
    )
);

ezinteger

$contentCreateStruct->setField('length',(int) $value);

ezselection

0: first occurrence in the selection list

$contentCreateStruct->setField('difficulty',array(
        'selection' => 0
    )
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment