Symfony CMF Media Bundle - Could not load type "cmf_media_image" - image-uploading

I want to use the CMF Media Bundle for image uploads. The Bundle was installed successfully.
routing.xml
cmf_media_file:
resource: "#CmfMediaBundle/Resources/config/routing/file.xml"
cmf_media_image:
resource: "#CmfMediaBundle/Resources/config/routing/image.xml"
AppKernel.php
$bundles = array(
...
new Symfony\Cmf\Bundle\MediaBundle\CmfMediaBundle(),
);
Now I want to add the following code to my form:
$builder
-> add('image', 'cmf_media_image', array('required' => false))
;
But I get an error message:
Could not load type "cmf_media_image"
What did i miss?

Maybe you should declare the template like this (in config.yml) :
twig:
form:
resources:
- 'CmfMediaBundle:Form:fields.html.twig'
see http://symfony.com/doc/current/cmf/bundles/media/form_types.html for more info

Related

Puppet-hiera-Function lookup() did not find a value-Windows

I installed dsc module and added AD user to Domain controller using puppet. Code below works fine when hard-coding password as plain text. Is it possible somehow to encrypt those passwords.
I read that hiera-eyaml is solution for this so i encrypted password
[root#PUPPET puppet]# /opt/puppetlabs/puppet/bin/eyaml encrypt -p
Enter password: **********
string: ENC[PKCS7,MIIBeQYJKoZIhvcNAQcDoIIBajCCAWYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAl/+uUACl6WpGAnA1sSqEuTp39SVYfHc7J0BMvC+a2C0YzQg1V]
Then stored that encrypted pass in /etc/common.eyaml file (specified in hiera config file)
/opt/puppetlabs/puppet/bin/eyaml edit /etc/common.eyaml
I can decrypt the file successfully:
/opt/puppetlabs/puppet/bin/eyaml decrypt -f /etc/common.eyaml
Then i specified encrypted pass to manifest file
/etc/puppetlabs/code/environments/production/manifests/site.pp:
dsc_xADUser {'FirstUser':
dsc_ensure => 'present',
dsc_domainname => 'ad.contoso.com',
dsc_username => 'tfl',
dsc_userprincipalname => 'tfl#ad.contoso.com',
dsc_password => {
'user' => 'Administrator#ad.contoso.com',
'password' => Sensitive('pass')
},
dsc_passwordneverexpires => true,
dsc_domainadministratorcredential => {
'user' => 'Administrator#ad.contoso.com',
'password' => Sensitive(lookup('password'))
},
}
On windows node i got error
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Function lookup() did not find a value for the name 'password' on node windows.example.com
Hiera config file:
cat /etc/puppetlabs/puppet/hiera.yaml
---
# Hiera 5 Global configuration file
---
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:
- name: "Eyaml hierarchy"
lookup_key: eyaml_lookup_key # eyaml backend
paths:
- "/etc/common.eyaml"
options:
pkcs7_private_key: "/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem"
pkcs7_public_key: "/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem"
cat /etc/common.eyaml
password: ENC[PKCS7,MIIBeQYJKoZIhvcNAQcDoIIBajCCAWYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAl/+uUACl6WpGAnA1sSqEuTp39SVYfHc7J0BMvC+a2C0YzQg1V]
I'm new to Puppet and this hiera is confusing me
For starters, there is a typo in your Hiera config file. The path to the data should be:
paths:
- "/etc/common.eyaml"
After fixing that, you need to retrieve the value from Hiera. This is performed with the puppet lookup function. Since you have a single key value pair here in a single data file, this can be performed with a minimal number of arguments.
dsc_xADUser {'FirstUser':
dsc_ensure => 'present',
dsc_domainname => 'ad.contoso.com',
dsc_username => 'tfl',
dsc_userprincipalname => 'tfl#ad.contoso.com',
dsc_password => {
'user' => 'Administrator#ad.contoso.com',
'password' => Sensitive('pass')
},
dsc_passwordneverexpires => true,
dsc_domainadministratorcredential => {
'user' => 'Administrator#ad.contoso.com',
'password' => lookup('string'),
},
}
However, you also really want to redact that password from your logs and reports. You would want to wrap that password String in a Sensitive data type.
'password' => Sensitive(lookup('string')),
You seem to already be doing that for your other password that is being passed in as a String pass.
A side note to all of this is that Puppet has intrinsic support for lookup retrievals from Vault and Conjur in version 6, so that will become best practices instead of hiera-eyaml soon.
Ufff, after much struggling finally got it working:
cat /etc/puppetlabs/puppet/hiera.yaml
---
version: 5
defaults:
datadir: data
data_hash: yaml_data
hierarchy:
- name: "Eyaml hierarchy"
lookup_key: eyaml_lookup_key # eyaml backend
paths:
- "nodes/%{trusted.certname}.yaml"
- "windowspass.eyaml"
options:
pkcs7_private_key: "/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem"
pkcs7_public_key: "/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem
Created password:
/opt/puppetlabs/puppet/bin/eyaml encrypt -l 'password' -s 'Pass' --pkcs7-public-key=/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem --pkcs7-private-key=/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
Added it to /etc/puppetlabs/puppet/data/windowspass.eyaml file:
/opt/puppetlabs/puppet/bin/eyaml edit windowspass.eyaml --pkcs7-public-key=/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem --pkcs7-private-key=/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
cat /etc/puppetlabs/puppet/data/windowspass.eyaml
---
password: ENC[PKCS7,MIIBeQYJKoZIhvcNAQcDoIIBajCCAWYCAQAxggEhMIIBHQIBADAFMAACAQEwDQYJKoZIhvcNAQEBBQAEggEAUopetXenh/+DN1+VesIZUI5y4k3kOTn2xa5uBrtGZP3GvGqoWfwAbYsfeNApjeMG+lg93/N/6mE9T59DPh]
Tested decryption:
/opt/puppetlabs/puppet/bin/eyaml decrypt -f windowspass.eyaml --pkcs7-public-key=/etc/puppetlabs/puppet/keys/public_key.pkcs7.pem --pkcs7-private-key=/etc/puppetlabs/puppet/keys/private_key.pkcs7.pem
As Matt suggested, mapped content of windowspass.eyaml to manifest file
'password' => Sensitive(lookup('password'))
Debugging command helped me a lot:
puppet master --debug --compile windows.example.com --environment=production
Thanks everyone, especially to Matt

Class 'Modules\Media' not found in eval()'d code on line 1 in Laravel after installing laravel-modules by nWidart

I'm using nWidart's laravel-modules for a project. The idea is great but I don't like having the modules directory starting with a capital letter (Modules).
I decided to change the directory name in the configuration file:
/config/modules.php
I kept the namespace as Modules, but I changed path:
return [
'namespace' => 'Modules',
'paths' => [
'modules' => base_path('modules'), // Used to be ('Modules')
]
];
I added this to the composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
Now, I created a Module called Media:
php artisan module:make Media
And also created a model Media:
php artisan module:make-model Media media
My model goes like this:
<?php
namespace Modules\Media\Entities;
use Illuminate\Database\Eloquent\Model;
class Media extends Model{
//
public function categories(){
return $this->belongsToMany( Category::class, 'category_media' );
}
}
Everything works fine, but when I go to tinker
php artisan tinker
And I try to load an Object (which exists) from the database:
$file = \Modules\Media\Entities::find( 1 );
or
$file = Modules\Media\Entities::find( 1 );
or
$file = modules\Media\Entities::find( 1 );
or
$file = \modules\Media\Entities::find( 1 );
I get this error:
PHP Fatal error: Class 'Modules\Media\Entities' not found in eval()'d code on line 1
Any ideas on what might be causing the problem? was it the changeof the directory name? Am I missing something in the composer.json configuration? I have no idea.
After reading my own code, I figured out that I was not referencing the Class, but only the namespace. The correct way to call the Media class was:
$file = \Modules\Media\Entities\Media::find( 1 );
(Notice that this time I end with \Media)
And of course, the result is the expected:
=> Modules\Media\Entities\Media {#857
id: 1,
filename: "my_file.jpg",
properties: "[]",
mime: "image\jpg",
extension: "jpg",
created_at: "2017-05-21 04:37:28",
updated_at: "2017-05-21 04:37:28",
published: 0,
published_at: "2017-05-20 23:37:28",
}

tymon jwt-auth laravel 5.4 error

I am getting this error after composer update....
I am using laravel version 5.4.*
Call to undefined method Illuminate\Foundation\Application::share()
My providers array
`'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'
],`
My alias array
'aliases' => ['View' => Illuminate\Support\Facades\View::class,
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',
'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory'
],
My composer.json
,
"tymon/jwt-auth": "0.5.*"
The error is
C:\wamp\www\myproject\app>php artisan vendor:publish --provider="Tymon\JW
TAuth\Providers\JWTAuthServiceProvider"
PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::sh
are() in C:\wamp\www\myproject\app\vendor\tymon\jwt-auth\src\Providers\JW
TAuthServiceProvider.php on line 122
Use dev-master branch. Edit yout composer json file.
"require": {
...
"tymon/jwt-auth": "dev-master"
...
},
and composer update
When you want to add a provider in app.php the code is like this:
ProviderPath/ProviderName::class,
Change this line:
'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'//this one
],
to
'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class //this one
],

how to integrate htmlpurifier with symfony2?

I am trying to integrate htmlpurifier into a symfony2 controller, but symfony2 assumes the class I am trying to instantiate is part of that vary controller, but it is not, it is an included class type frmo the htmlpurifier library.
Is there a way to escape the class name so that symfony2 doesn't look for it in the current namespace?
I suggest to use the bundle version of HTMLPurifier for symfony2
you can found it on gitHub : https://github.com/Exercise/HTMLPurifierBundle
it's pretty easy to install with composer
Require the bundle in your composer.json file:
{
"require": {
"exercise/htmlpurifier-bundle": "*",
}
}
Install the bundle:
$ composer update exercise/htmlpurifier-bundle
Register the bundle app/AppKernel.php :
public function registerBundles()
{
return array(
new Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle(),
// ...
);
}
you can use it as a service in a controller :
$purifier = $this->container->get('exercise_html_purifier.default');
$clean_html = $purifier->purify($dirty_html);
or a filter in a twig template :
{{ text|purify }}
also a Form Data Transformer for the symfony2 form builder
it's all in the docs : https://github.com/Exercise/HTMLPurifierBundle
Oh, just found it.
Instead of
require_once dirname('_FILE_') . '/plugins/htmlpurifier/library/HTMLPurifier.auto.php';
$purifier = new HTMLPurifier();
I should put a leading backslash on the class name
require_once dirname('_FILE_') . '/plugins/htmlpurifier/library/HTMLPurifier.auto.php';
$purifier = new \HTMLPurifier();

Symfony "Could not load type" service yaml

I tried to create a service in Symfony 2.2 for one of my form :
service.yml:
tyg_user.settings.form:
class: Symfony\Component\Form\Form
factory_method: createNamed
factory_service: form.factory
arguments:
- tyg_user_settings
- tyg_user_settings_name
tyg_user.settings.form.type:
class: TyG\UserBundle\Form\Settings\SettingsFormType
tags:
- { name: form.type, alias: tyg_user_settings }
tyg_user.settings.form.handler:
class: TyG\UserBundle\Form\Settings\SettingsFormHandler
scope: request
arguments:
- #tyg_user.settings.form
- #request
- #fos_user.user_manager
SettingsForm.php
<?php
namespace TyG\UserBundle\Form\Settings;
use Symfony\Component\Form\FormBuilderInterface as FormBuilder;;
use Symfony\Component\Form\AbstractType;
class SettingsForm extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('birthday', 'birthday')
->add('email', 'email')
->add('showmail')
->add('showbirthday')
;
}
public function getName()
{
return 'tyg_user_settings';
}
}
?>
But an error occuered :
Could not load type "tyg_user_settings_name
This occurs when I get my form through the service container :
$this->container->get('tyg_user.settings.form');
I used to do create my service through the xml format but when I change to the yml format I can't figure out how to to make it works
The tyg_user_settings_name is referencing a form type alias.
If you are wanting it to reference a parameter you should use %tyg_user_settings_name% instead.