I have a form which contains kartik fileInput. This is how my form looks like:
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'layout' => 'horizontal',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-4',
'offset' => 'col-sm-offset-2',
'wrapper' => 'col-sm-15'
],
],
]); ?>
<div class="form-label-group">
<?= $form->field($model, 'model')->textInput(['autofocus' => true, 'class' => 'form-control', 'id' => 'inputEmail'])->label('PHONE MODEL:') ?>
</div>
<div class="form-label-group">
<?= $form->field($model, 'name')->textInput(['class' => 'form-control', 'id' => 'inputEmail'])->label('PHONE MODEL NAME:') ?>
</div>
<div class="form-label-group">
<?= $form->field($model, 'price')->textInput(['class' => 'form-control', 'id' => 'inputEmail'])->label('PRICE:') ?>
</div>
<div class="form-label-group">
<?= $form->field($model, 'description')->textarea(['class' => 'form-control', 'id' => 'inputEmail'])->label('DESCRIPTION:') ?>
</div>
<?php echo $form->field($model, 'file[]')->widget(FileInput::classname(), [
'options' => ['accept' => 'image/*','multiple' => true]
]); ?>
<?= Html::submitButton('ADD', ['class' => 'btn btn-lg btn-block add-btn mt-4']) ?>
<?php ActiveForm::end(); ?>
I have my Kartik CSS/JS in the same asset as my other stylesheets. This is my asset:
<?php
namespace app\assets;
use yii\web\AssetBundle;
class DashboardAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'css/dashboard/c3.min.css',
'css/dashboard/dashboard1.css',
'css/dashboard/morris.css',
'css/dashboard/style.css',
'//fonts.googleapis.com/css?family=Lobster&display=swap',
// Kartik fileInput
'css/kartik-fileInput/fileinput.css',
'css/kartik-fileInput/theme.css'
];
public $js=[
'js/dashboard/bootstrap.min.js',
'js/dashboard/c3.min.js',
'js/dashboard/custom.min.js',
'js/dashboard/d3.min.js',
'js/dashboard/dashboard1.js',
'js/dashboard/jquery-3.2.1.min.js',
'js/dashboard/jquery.sparkline.min.js',
'js/dashboard/morris.min.js',
'js/dashboard/perfect-scrollbar.jquery.min.js',
'js/dashboard/popper.min.js',
'js/dashboard/raphael-min.js',
'js/dashboard/sidebarmenu.js',
'js/dashboard/waves.js',
// Kartik fileInput
'js/kartik-fileInput/file.js',
'js/kartik-fileInput/es.js',
'js/kartik-fileInput/fileinput.js',
'js/kartik-fileInput/fr.js',
'js/kartik-fileInput/piexif.js',
'js/kartik-fileInput/sortable.js',
'js/kartik-fileInput/theme.js',
'js/kartik-fileInput/theme2.js'
];
//if this asset depends on other assets you may populate below array
public $depends = [
];
}
The problem is that when I echo out the fileInput, it messes entire form's CSS up. After commenting the
<?php echo $form->field($model, 'file[]')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*','multiple' => true]]); ?> part, the styles are back to normal. How can I fix this problem so the fileInput doesn't overwrite custom CSS?
This is how my form looks like before/after adding the fileInput widget.
Before: https://imgur.com/wAdgeHz
After: https://imgur.com/yqe8yM8
Try setting
Yii::$app->params['bsDependencyEnabled'] = false
in your params.php file. This will prevent the loading of bootstrap css and js asset files.
source: http://demos.krajee.com/widget-details/fileinput#override-bootstrap-cssjs
Related
I am taking data from a config form and passing it to a .tpl file to display.
I am using hook_block_view() to take the data, put it into an array and send it to the .tpl file.
My code (on .module) is as such:
/**
* Implements hook_block_info().
*/
function message_block_info() {
return [
'message_block' => [
'info' => t('Message'),
'cache' => DRUPAL_CACHE_GLOBAL,
],
];
}
/**
* Implements hook_theme().
*/
function message_theme() {
return [
'message_block' => [
'template' => 'templates/message-block',
'variables' => [
'settings' => NULL,
'attributes' => [],
],
],
];
}
/**
* Implements hook_block_view().
*/
function message_block_view($delta = '') {
if ($delta !== 'message_block') {
return;
}
$config = message_default_settings();
dpm($config); // <- this shows correct data
$block['content'] = array(
'#theme' => 'message_block',
'#config' => array(
'message_text' => filter_xss($config['message_text']),
'message_link' => filter_xss($config['message_link']),
'message_button_text' => filter_xss($config['message_button_text']),
),
);
return $block;
}
And on the .tpl file:
<?php dpm('test'); //<- This works ?>
<?php dpm($config); //<- This does not work?>
<div class="message">
<?php print $config['message_text']; ?>
<?php if (!empty($config['message_link']) && !empty($config['alert_button_text'])): ?>
<a href="<?php print $config['message_link']; ?>" class="button">
<?php print $config['message_button_text']; ?>
</a>
<?php endif; ?>
</div>
I can place a dpm('test'); on the .tpl file and it will appear, so I know that the HTML is rendering. Obviously, I've tried clearing cache, too.
Would anyone know if I've missed a step to get this data appearing?
I found I was missing the config array initilisation in hook_theme:
function message_theme() {
return [
'message_block' => [
'template' => 'templates/message-block',
'variables' => [
'config' => NULL, //<- Was missing
],
],
];
}
This used to work for me without fail when Drupal 8 first came out. However this does not seem to work anymore and I get an error. Drupal docs have always been horrid so no solution there.
custom.module
<?php
function custom_theme() {
$theme['home_page'] = [
'variables' => ['name' => NULL],
'template' => 'home_page'
];
return $theme;
}
function custom_menu(){
$items = array();
$items['admin/config/system/custom'] = array(
'title' => 'Custom',
'description' => 'Configuration Custom',
'route_name' => 'custom.settings'
);
return $items;
}
custom.routing.yml
custom.home:
path: /home
defaults:
_controller: Drupal\custom\Controller\RoutingController::home
requirements:
_permission: 'access content'
src/Controller/RoutingController.php
<?php
namespace Drupal\custom\Controller;
class RoutingController {
public function home(){
return array(
'#title' => 'Home',
'#theme' => 'home_page'
);
}
}
home_page.html.twig
<main>
<!-- some markup -->
</main>
your controller not extending the base controller class problem one
try this
namespace Drupal\custom\Controller;
use Drupal\Core\Controller\ControllerBase;
class RoutingController extends ControllerBase{
public function home(){
return array(
'#title' => 'Home',
'#theme' => 'home_page'
);
}
}
home_page.html.twig
<main>
<!-- some markup -->
{{ content }}
</main>
also try to extend you theme hook with path
'path' => drupal_get_path('module', 'custom') . '/templates',
and place your template twig file in your module/templates folder
How i can intregate Growl Widget Kartik Yii2 with AdminLTE Template. When i used the widget not show the animation and position defined from Controller.
CompraController.php
... if ($flag) {
$transaction->commit();
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'glyphicon glyphicon-ok',
'message' => ' Compra Registrada ;)',
'title' => 'Registro Compra',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['index']);
}
main.php
... <?php foreach (Yii::$app->session->getAllFlashes() as $message):; ?>
<?php
echo Growl::widget([
'type' => (!empty($message['type'])) ? $message['type'] : 'danger',
'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Title Not Set!',
'icon' => (!empty($message['icon'])) ? $message['icon'] : 'fa fa-info',
'body' => (!empty($message['message'])) ? Html::encode($message['message']) : 'Message Not Set!',
'showSeparator' => true,
'delay' => 1, //This delay is how long before the message shows
'pluginOptions' => [
'delay' => (!empty($message['duration'])) ? $message['duration'] : 3000, //This delay is how long the message shows for
'placement' => [
'from' => (!empty($message['positonY'])) ? $message['positonY'] : 'top',
'align' => (!empty($message['positonX'])) ? $message['positonX'] : 'right',
]
],
'useAnimation'=>true
]);
?>
<?php endforeach; ?>
When i use the normal template of Yii2 works fine:
But when i use the AdminLTE template, every option is trated like a different notification:
Apparently the AdminLTE Template it has its own notification methods that prevent the execution of Growl Widget. I remove the line:
<?= Alert::widget() ?> in:
<section class="content">
<?= Alert::widget() ?>
<?= $content ?>
</section>
from the file views/layout/content.php and works fine.
I have a the register button which I have created in cgridview I need to know whether can we have action in controller buuton and no view for that particular action for that button in yii
view user
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(
'name',
'email',
array(
'class'=>'CButtonColumn',
'template'=>'{Register}{update}{view}',
'buttons'=>array(
'Register'=>array(
'label'=>'Register',
.'url'=>Yii::app()->createUrl('register/create',array( 'email'=>$data->email) )
)
),
),
),
)); ?>
controller user
public function actionCreate($email)
{
$model=$this->loadModel($email);
if($_SESSION['userid'])
{
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
));
}
//$this->redirect(array('display','id'=>$model->productid));
$this->redirect(array('user/login'));
}
i don get error but then the below line not the url iam looking
/localhost/test/index.php/register/create/product/create
it should be
/localhost/test/index.php/product/create/id/1
i think there's something wrong in line 1
Please let me know how do i resolve this
change this
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
to
$this->redirect(Yii::app()->createUrl('product/create',array( //line 1
'id'=>$model->productid))
You can parametrise your individual CButtonColumn instances:
array(
'class' => 'CButtonColumn',
'template' => '{Register}{view}{update}',
'buttons' => array(
'Register' => array(
'label' => 'Register',
'url'=>Yii::app()->createUrl('register/create', array('email' => $data->email)),
'visible'=>'$data->entries == 0',
),
'view' => array(
'visible'=>'$data->entries > 0',
)
)
),
But to answer you question after you updated your response (I was already typing it out)
You can use the raw type:
'type'=>'raw',
and the url becomes something like :
'url'=>'Yii::app()->createUrl("register/create",array( "email"=>$data->email) )'
thx to #let-me-see
source: http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/#hh2
this works
$this->redirect(array('product/create','id'=>$model->productid));
I went to this tutorial. I got the example to work. But I don't get it because I can't customize it for my case.
I want to display a picture for each of my facebook friend and pass the adress of the profile picture from facebook to an image tag in front of the checkbox element.
Update
part of my action:
//the array is on part of my update.
$choice_test = array();
$choice_test[] = array('id' => 1, 'username' => 'test');
$choice_test[] = array('id' => 2, 'username' => 'test2');
->add('friend', 'choice', array(
'required' => true,
'expanded' => true,
'choice_list' => $choice_test, //this is my update
'choices' => $fb_friends_form, //$fb_friends_form[1]= 'First Lastane';
'multiple' => true,
'constraints' => array(new CheckChoicesFbFriends(array('fb_friends_form' => $fb_friends_form))),
'mapped' => true
))
return $this->render('FrontendChancesBundle::createrequest.html.php', array(
'form' => $form->createView()));
template:
<?php $view['form']->setTheme($form, array('FrontendDemoBundle:Form')) ;?>
<?php echo $view['form']->widget($form['friend'])?>
in FrontendDemoBundle/Ressources/views/Form/form_widget_pics.html.php:
<input
type="<?php echo isset($type) ? $view->escape($type) : 'checkbox' ?>"
<?php if (!empty($value)): ?>value="<?php echo $view->escape($value) ?>"<?php endif ?>
<?php echo $view['form']->block($form, 'checkbox_widget') ?>
/>
How can I pass even a variable, in my case the username (`$fb_username[0] = 'username' of facebook to from_widget_pics.html.php and how can I display it like this with the form bulider in my aciton:
<img src="www.facebook.com/+FirstLastname>
<input type="checkbox"
id="form_friend_0"
name="form[friend][]"
value="1"/>
<label for="form_friend_0" >First Lastname</label>
<img src="www.facebook.com/+nextfriend>
I had the very same exception message when trying to pass an array or collection of custom selected objects to a form using 'choice_list' option.
I solved it this way (simplified example):
Controller code:
use Symfony\Component\Form\Extension\Core\ChoiceList\SimpleChoiceList;
class UsedCarsController extends Controller {
..... action code:
$usedCars = $carRepository->findAllUsed();
$choiceList = new SimpleChoiceList($usedCars);
$form = $this->createForm(new UsedCarsType($choiceList),null, array('label' => 'Used cars form'));
... now render view, etc.
UsedCarsType:
class UsedCarsType extends AbstractType
{
private $choicesList;
public function __construct($choicesList)
{
$this->choicesList = $choicesList;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('usedCars', 'choice',array('label'=>'Used cars',
'required'=>true,
'choice_list' => $this->choicesList,
'empty_value' => '-- used car --'))
;
}
Choice_list option must be an instance of SimpleChoiceList class, not an array.
A bit late but hope this helps.
BTW: I am using Symfony 2.3