Symfony 2 - Polymorphism - symfony

Consider the following scenario:
Test class:
class Test{
protected $title;
protected $description;
}
Base Question class:
class BaseQuestion{
protected $Test
protected $question;
}
Text Question class:
class TextQuestion extends BaseQuestion{
}
Checkbox Question class:
class CheckboxQuestion extends BaseQuestion{
protected $options;
}
So I have all this setup, now I need an easy way for people to create new tests with questions.
I first started by using Sonata Admin as a CMS, which was working fine as long as I didn't use polymorphism and just used 1 type of question. Using the inline option you could create questions when you were creating test. However including the inheritance to Sonata Admin with their inline option proved to be unsuccessful.
I then tried to remove all the Sonata Admin stuff and just build a plain form to do this but again, with only 1 type of question this works very well with embedded forms. But as soon as I tried implementing it with the inheritance classes, things proved more difficult.
I tried using the Infinite PolyCollection Bundle but couldn't find anything on how to display the form. I then found the Arse Polycollection bundle (which uses the Infinite bundle) but can't get it to work even though I was following the tutorial step by step.
Currently it's giving me the following error:
FatalErrorException: Error: Call to undefined method Symfony\Component\Form\FormBuilder::getTypes()
I am getting clueless on how to proceed with this, has anyone got the above bundles working before?
Or do you have other suggestions on how to set up a (small) CMS system for this?
Update:
I basically did everything manual now and it's working but I do hope they include a way of doing this with the framework in the future.

Related

Could not navigate to "view"

I am using vaadin 10. I would see this error on my login view class if I used #Route("") but when I write it as #Route(value="") it worked. But doing that to another view I get this error. Most questions asked are way too advanced. I just have a simple project with vaadin and springboot.
With the source code you provided as link in the question's comments, I cannot reproduce your issue. However, there were 2 problems with your code before I was able to run the application:
the #Theme annotation needs to be placed on a view or router layout; I moved it to your LoginView
the Valo theme is not available in Vaadin 10, so the reference on ValoTheme class was a compile error; I removed it
After fixing these problems everything ran fine, #Route(value="") and #Route("") were both working. Which Java version are you using? Java 8 is required minium for Vaadin 10. Also please try to remove lombok for testing, maybe it is causing a problem.
Try annotating your EmployeeDisplay class with #Route(value = "employeeDisplay") instead of #Route(value = "/employeeDisplay"). In other words, remove the /.

How can I override Request class?

I tried overriding the core classes but this one doesnt seem to work. I know I will need to update the application/config/app.php file to point to the new class. But when I do this the HTML redender stops at head tag.
I extended the Request Class from core to application/src, updated the app.php file, but it doest work and gives me a blank page. I will need this to use redirect url.
if your goal is to do something to the request before sending it back you might want to use a middleware instead of overriding the class.
A good example is the Centry portal package which you can find here: https://github.com/a3020/centry
Have a look at centry\Provider\CentryServiceProvider.php function registerMiddleware() to see how to register a middleware.
And then look at the 2 files in centry\Http\Middleware to see how it's used.
If you are using version 8 you will need to autoload your classes in the src folder.
In application/bootstrap/autoload.php
$classLoader = new \Symfony\Component\ClassLoader\Psr4ClassLoader();
$classLoader->addPrefix('Application\\Example', DIR_APPLICATION . '/' . DIRNAME_CLASSES . '/Example');
From here you will need to override the associated service provider. It's not entirely clear which class you are trying to override and which service provider this would require. Below is an example for overriding the \Concrete\Core\Http\HttpServiceProvider with class placed in application/Src/Example/HttpServiceProvider
return [
'providers' => [
'core_http' => 'Application\Example\HttpServiceProvider'
]
]
From the service provider you can extend classes and override the returned classes in a way the suits your use case scenario (It can be tedious if multiple classes have references but it's the only way I'm aware of to properly override core classes). Typically you can just extend existing classes overriding a single method or two and come up with an elegant solution.

Working with custom routes in wp-mvc plugin

I’ve been trying to develop large scale application in wordpress. Been through several plugin development best practices. And finally I’ve been reading the documentation of http://wpmvc.org/
I pretty much understood its automatic (mvc) code generation tools. Its default controller functions index() & show() works pretty well.
But, when I tried to add a custom_action(), thats where I got stuck.
class DemoController extends MvcPublicController {
public function hello(){
print_r($this->params);
die();
}
}
above function hello() is only accessible by below URL:
domain.com/demo/hello/{num}
but can’t be accessed via:
domain.com/demo/hello
Do I need to write any custom route to make this work? Or, am I doing anything wrong?
Finally, I found the solution, and it was pretty easy.
In config/routes.php,
I replaced, this:
MvcRouter::public_connect('{:controller}/{:action}/{:id:[\d]+}');
with this:
MvcRouter::public_connect('{:controller}/{:action}');
[ IMPORTANT ] Don't forget to save permalinks to flush rewrite rules.

GWT NativeVerticalScrollbar CSS example

I just discovered the "CustomScrollPanel" and it seems to be a great piece of GWT. I also noticed that is is also possible to add a custom "NativeVerticalScrollbar".
However, I could not find out so far how to apply CSS to this object. I searched the web but did not find anything. In the source repository on github I discovered the file https://github.com/gwtproject/gwt/blob/master/user/src/com/google/gwt/user/client/ui/NativeVerticalScrollbar.css however, it is empty.
So, can anybody please give an example what kind of css can be applied in order to style the scrollbar?
You you familiar with ClientBundle? Take a look at the source code of the CustomScrollPanel or the NativeVerticalScrollbar
They both have a declarion of a Resources interface, all you need to do is to extend this interface and bundle a new CSS (or GSS) with your style.
This is the current Resources interface for the NativeVerticalScrollbar
/**
* A ClientBundle of resources used by this widget.
*/
public interface Resources extends ClientBundle {
/**
* The styles used in this widget.
*/
#Source(Style.DEFAULT_CSS)
Style nativeVerticalScrollbarStyle();
}
Create the CSS (or GSS) that you want, customize it away. It has to respect the Style Interface declaration (and the compiler fails if you don't)
public interface MyNewResource extends com.google.gwt.user.client.ui.NativeVerticalScrollbar.Resource {
/**
* The styles used in this widget.
*/
#Source("/PATH_TO_YOUR_CSS/newCss.css")
com.google.gwt.user.client.ui.NativeVerticalScrollbar.Style nativeVerticalScrollbarStyle();
}
Then when you create a new widget, just pass MyNewResource instance to the widget
MyNewResource resources = GWT.create(MyNewResource.class)
NativeVerticalScrollbar myScrollBar = new NativeVerticalScrollbar(resources);

Is there an "extended" UIHint attribute to apply CSS styles for DisplayFor - EditorFor templates?

Intro: After reading Brad Wilson Metadata series and searching unsuccesfully on google, I was wondering:
Question: Has any OS project / code been created that allows you to tag CSS styles in the Meta information, for example in my (buddy) Model, I want to be able to decorate a property with multiple CSS styles (a single style you can fake with UIHint, I want to set many possible styles - and be able to "cross-utilise")
eg.
public class MyModel
{
[DisplayCssHint("h5")]
[DisplayCssHint("color:#777;")]
[EditorCssHint(".myCoolTextClass")]
[EditorCssHint(".myOtherCoolTextClass")]
public string Title{ get;set; }
[DisplayCssHint(".normaltext")]
[EditorCssHint(".myCoolTextClass")]
[EditorCssHint(".myOtherCoolTextClass")]
public string Message {get;set;}
}
Thoughts: I know that this does not seem like a logical place to put styling information, however as it is metadata and is discriptive... besides it would be nice to do this while prototyping - (especially being able to apply class styles and extending it further - to generate .Less files would really be cool! more to the point I would hate to write it, if its already been done ;). Any links/pointers/idea's would be appreciated.
Thanks,

Resources