Setting body classes in Zend - css

I am working on a Zend 1.12 application and trying to get style classes assigned to layout body tag.
I found this sample Bootstrap.php file that seems to handle the task:
https://gist.github.com/fideloper/1302688
It seems to integrate nicely, but the body's class always comes out blank.
Can someone please point me in the right direction here on how to get classes assigned to body?
Thanks.

Made a small change to the snippet I referenced above.
class AppName_Helper_BodyClass extends Zend_View_Helper_Placeholder_Container_Standalone {
private $_classes = array();
public function __construct($classes = null) {
if(is_array($classes)) {
$this->addClass($classes);
}
}
public function addClass($class) {
if(is_array($class)) {
foreach($class as $k => $c) {
if(is_string($c)) {
if(is_string($k)) {
$this->addClass($k.'-'.$c); //recursion
} else {
$this->addClass($c);
}
} else {
throw new Zend_Exception('Class must be a string - is type: '.gettype($c));
}
}
return $this;
}
if(is_string($class)) {
$this->_classes[] = $class;
return $this;
} else {
throw new Zend_Exception('Class must be a string - is type: '.gettype($class));
}
return $this;
}
public function removeClass($class) {
$key = array_search($class, $this->_classes);
if($key !== false) {
unset($this->_classes[$key]);
}
return $this;
}
public function bodyClass() {
return $this;
}
public function toString() {
return implode(' ', $this->_classes);
}
}
This snippet goes into my layout:
$uri = Zend_Controller_Front::getInstance()->getRequest()->getParams();
$this->bodyClass()->addClass($uri);
The results is such (for module - "default", controller - "auth", action - "signin"):
<body class="controller-auth action-signin module-default">
I am grabbing current request's parameters and mapping them to the body class. Hope this helps someone dealing with this.

From the look of that helper you need to call one of it's methods to add a class. From one of your controllers:
$this->view->bodyClass()->addClass('something');
is that how you are using it?

Related

Widget Elementor that adds a Div to body using hook

Is there a way to add a div to body when the Widget is rendered? Like using a hook 'wp_body_open' or something.
Where can I put a hook in Widget_Base extended class for it?
I'm using a common Class like:
use Elementor\\Widget_Base;
use Elementor\\Controls_Manager;
class MenuHamburguer extends Widget_Base
{
public function __construct($data = [], $args = null)
{
parent::__construct($data, $args);
// I've tried here, but no success.
}
public function get_name()
{
return 'menu-hamburguer';
}
public function get_title()
{
return __('Menu Hamburguer', 'later');
}
public function get_icon()
{
return 'fa fa-bars';
}
public function get_categories()
{
return ['later'];
}
protected function _register_controls()
{
// do normal stuff of the widget...
}
protected function render()
{
// do normal stuff of the widget...
}
}

Twig extension for sorting Doctrine ArrayCollection

I'm trying to write a Twig filter to be able to sort a Doctrine ArrayCollection, but the returned array is not sorted :( Can you please help me to fix this:
class SortExtension extends \Twig_Extension
{
public function getFilters()
{
return array(
new \Twig_SimpleFilter('sortby', array($this, 'sortByFilter')),
);
}
public function sortbyname( $a, $b )
{
if ($a->getName() === $b->getName()) {
return 0;
}
if ( $a->getName() < $b->getName() ) {
return 1;
}
return -1;
}
public function sortByFilter($collection)
{
$iterator = $collection->getIterator();
$iterator->uasort(array($this, 'sortbyname'));
return $collection;
}
I'm not quite sure if the returned collection in sortByFilter is changed.
This is because you are getting the iterator and sorting it.
The method getIterator creates a new ArrayIterator which makes a copy of the array.
Then, you are returning the collection, which is not sorted.
Here is a little sample of what happens.
You just have to replace
return $collection;
By
return $iterator;

Is there any way to determine current action (create or edit) in Sonata\AdminBundle\Admin\Admin::configureFormFields()?

I'd like to create different fields configuration for create and edit actions in Sonata Admin Bundle.
Is there any way to determine it except checking $this->getSubject()->getId() in Sonata\AdminBundle\Admin\Admin::configureFormFields()?
You can also do this:
protected function configureFormFields(FormMapper $formMapper) {
if ($this->isCurrentRoute('create')) {
// CREATE
}
else {
// EDIT
}
}
with:
if($this->getRequest()->get($this->getIdParameter()) == null){
// create
} else {
// edit
}
I use this :
$creationMode = ($this->id($this->getSubject()))?(false):(true);
if ($creationMode){
//Ok
}
In sonata admin from version 3.x
if ($this->isCurrentRoute('create')) {
// CREATE
}
else {
// EDIT
}
In sonata admin before version 3.x use:
$subject = $this->getSubject();
if ($subject->isNew()) {
// CREATE
}
else {
// EDIT
}
You can also do this:
protected function configureFormFields(FormMapper $formMapper) {
if ($this->isCurrentRoute('create')) {
// CREATE
}
else {
// EDIT
}
}
public function getAction(): ?string
{
if (! $this->getRequest()) {
return null;
}
$pathArray = \explode('/', $this->request->getPathInfo());
return \end($pathArray);
}

Symfony2 + Twig: Translate label into a new twig extension

I have implemented a new twig extension and I have some text which had to be translated.
Unfortunately when I use a code label it appears as a sample text.
I mean when twig render this following extension, it displays: 5 entity.years instead of 5 years for example:
class MyExtension extends \Twig_Extension {
public function getFilters()
{
return array(
'myextension' => new \Twig_Filter_Method($this, 'myextension'),
);
}
public function myextension ($myId)
{
// ....
// Some operations concerning $myId...
// ....
if($myId!=0) {
$res = $myId. ' '.'entity.year';
} else {
$res = ($months == 0 ? $days.'entity.days' : $months.'entity.months');
}
return $res;
}
}
Where entity.years, entity.months, entity.days is defined into my translations folder.
Inject the translator service into your extension and use it. For example:
class MyExtension extends \Twig_Extension
{
private $translator;
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
// ...
public function myMethod()
{
return $this->translator->trans('my_string');
}
}

Finding out where TypeErrors are thrown

I am having a problem that is driving me nuts.
Recently I configured my BlazeDS to use Array instead of ArrayCollection for performance reasons. Additionally I adjusted my templates to generate Array properties.
Everything wen't fine. All except one function that causes TypeError: Error #1034. These are being thrown before the result callback is called. It claims to have problems casting an ArrayCollection to Array. I removed the generated types to make Flex use Objects instead, but these did not contain any ArrayCollections. My question now is: How can I get the stack-traces of errors thrown in event-handlers?
I allready added handlers for unhandledExceptions in all of my modules and they are called if errors occur in code triggered from user-interaction, but they don't seem to be able to catch stuff thrown by event-handlers.
How can I track these Errors?
Chris
PS: The classes are:
package de.upw.ps.ucg.model.ucg.scheduler {
[Bindable]
[RemoteClass(alias="de.upw.ps.ucg.model.ucg.scheduler.Task")]
public class Task extends TaskBase {
}
}
And:
package de.upw.ps.ucg.model.ucg.scheduler {
import de.upw.ps.ucg.model.oval.common.OvalVersionedIdentifier;
import flash.utils.IExternalizable;
[Bindable]
public class TaskBase {
public function TaskBase() {}
private var _aborted:Boolean;
private var _characteristicsId:String;
private var _currentExecutorPhase:JobExecutorPhase;
private var _definitionSetName:String;
private var _definitionSetVid:OvalVersionedIdentifier;
private var _endTime:Date;
private var _enqueueTime:Date;
private var _environmentId:String;
private var _environmentName:String;
private var _messages:Array;
private var _numberOfDefinitions:int;
private var _processedNumberOfTests:int;
private var _resultsId:String;
private var _schedulerJob:SchedulerJob;
private var _startTime:Date;
private var _statusMessage:String;
private var _taskId:String;
private var _totalNumberOfTests:int;
public function set aborted(value:Boolean):void {
_aborted = value;
}
public function get aborted():Boolean {
return _aborted;
}
public function set characteristicsId(value:String):void {
_characteristicsId = value;
}
public function get characteristicsId():String {
return _characteristicsId;
}
public function set currentExecutorPhase(value:JobExecutorPhase):void {
_currentExecutorPhase = value;
}
public function get currentExecutorPhase():JobExecutorPhase {
return _currentExecutorPhase;
}
public function set definitionSetName(value:String):void {
_definitionSetName = value;
}
public function get definitionSetName():String {
return _definitionSetName;
}
public function set definitionSetVid(value:OvalVersionedIdentifier):void {
_definitionSetVid = value;
}
public function get definitionSetVid():OvalVersionedIdentifier {
return _definitionSetVid;
}
public function set endTime(value:Date):void {
_endTime = value;
}
public function get endTime():Date {
return _endTime;
}
public function set enqueueTime(value:Date):void {
_enqueueTime = value;
}
public function get enqueueTime():Date {
return _enqueueTime;
}
public function set environmentId(value:String):void {
_environmentId = value;
}
public function get environmentId():String {
return _environmentId;
}
public function set environmentName(value:String):void {
_environmentName = value;
}
public function get environmentName():String {
return _environmentName;
}
public function set messages(value:Array):void {
_messages = value;
}
public function get messages():Array {
return _messages;
}
public function set numberOfDefinitions(value:int):void {
_numberOfDefinitions = value;
}
public function get numberOfDefinitions():int {
return _numberOfDefinitions;
}
public function set processedNumberOfTests(value:int):void {
_processedNumberOfTests = value;
}
public function get processedNumberOfTests():int {
return _processedNumberOfTests;
}
public function set resultsId(value:String):void {
_resultsId = value;
}
public function get resultsId():String {
return _resultsId;
}
public function set schedulerJob(value:SchedulerJob):void {
_schedulerJob = value;
}
public function get schedulerJob():SchedulerJob {
return _schedulerJob;
}
public function set startTime(value:Date):void {
_startTime = value;
}
public function get startTime():Date {
return _startTime;
}
public function set statusMessage(value:String):void {
_statusMessage = value;
}
public function get statusMessage():String {
return _statusMessage;
}
public function set taskId(value:String):void {
_taskId = value;
}
public function get taskId():String {
return _taskId;
}
public function set totalNumberOfTests(value:int):void {
_totalNumberOfTests = value;
}
public function get totalNumberOfTests():int {
return _totalNumberOfTests;
}
}
}
Both classes are generated by my maven build from a corresponding Java Class and the Types do fit together nicely.
Do you have access to the socket class that's reading in all these messages? Trace out the buffer before the deserialisation and you should at least be able to find the class that's giving you hassle.
Failing that, trace out the object after deserialisation and it should be the very first one after the error is thrown.
This is something you'll have to debug on your own, but I have a gut feeling that the problem is because the data being sent by your java DTO is not the same as your AS3 class, even though that you have the RemoteClass metadata saying that it is.
Are you missing a property? or have a property mismatch? That is the most likely cause of your error. I suggest you debug the java side as much as you can and use something like firebug to see the request/response of the server.

Resources