Problems with Shopware snippets - shopware

Greeting everyone !
I have a problem - snippets not works.
In Theme.php I use next
/**
* #param Form\Container\TabContainer $container
*/
public function createConfig(Form\Container\TabContainer $container)
{
$container->addTab($this->createBasicTab());
}
/**
* Create Basic Tab
* #return Form\Container\Tab
*/
public function createBasicTab()
{
$tab = $this->createTab(
'basic_settings',
'__basic_settings__',
[
'attributes' => [
'layout' => 'anchor',
'autoScroll' => true,
'padding' => '0',
],
]
);
In snippet located in _private/snippets/backend/config.ini I used next
[en_GB]
basic_settings = 'Basic settings'
[de_DE]
basic_settings = 'Basic settings de'
And in admin part I got next
Please, help!(

You can use it like this:
Shopware()->Snippets()->getNamespace('backend/config')->('__basic_settings__', 'There you can put value by deault')
Documentation for snippets.

In theme manager we have checkbox force snippet reload in settings. Please, enable it. This will save your nerves

Related

How to extend Tabulator with resizable column plugin

I thought this would be shown in the docs but I'm trying to get column resizing working with Tabulator.
This page just describes how to import the plugin:
import {ResizeTableModule} from 'tabulator-tables';
But what do you with this import? I thought you could add it to Tabulator.extendModule(ResizeTableModule) but that does nothing. I couldn't find any examples using plugins modularly like this. Thanks for the help.
To get column resizing working, you can import ResizeColumnsModule as follows:
import { Tabulator, ResizeColumnsModule } from "tabulator-tables";
Tabulator.registerModule(ResizeColumnsModule)
Example: https://codesandbox.io/s/gifted-wescoff-nw337l?file=/src/index.js
As per docs correct way to extend a module is like
/**
* #param {String} moduleName
* #param {any} configs
* #param {any} newconfig
*/
Tabulator.extendModule("resizeTable", "config", {
//Your New Config
name: "__int__",
});
I am afriad as ResizeTableModule module does not expose any other config but you can define them by extending the class
import { Tabulator, ResizeColumnsModule, ResizeTableModule } from "tabulator-tables";
class MyResizeTableModule extends ResizeTableModule {
constructor(table) {
super(table);
this.config = MyResizeTableModule.config;
}
}
MyResizeTableModule.config = {};
Tabulator.registerModule([MyResizeTableModule, ResizeColumnsModule]);
/**
* #param {String} moduleName
* #param {any} configs
* #param {any} newconfig
*/
Tabulator.extendModule("resizeTable", "config", {
//Your New Config
name: "__int__",
});
See Codesandbox

Codeigniter Version 4.1.7 Rest API Routing Post method not working

I am using Codeigniter Version 4.1.7.
Where I am implementing Rest API.
In the routes the GET method works,however Post method is not working.
I am testing this using POSTMAN.
URL : http://localhost/myproject/api/add-user
Following is the header
Accept: application/json
Content-Type: application/json
Authorization: Basic xxxxxxxxxxx=
Please check the code below for reference.
Routes.php
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false);
/*
* --------------------------------------------------------------------
* Route Definitions
* --------------------------------------------------------------------
*/
// We get a performance increase by specifying the default
// route since we don't have to scan directories.
//$routes->get('/', 'Home::index');
$routes->group("api", ["namespace" => "App\Controllers\Api", "filter" => "basicauth"] , function($routes){
$routes->get("list-users", "ApiController::index");
$routes->post("add-user", "ApiController::create");
});
ApiController.php
app\Controllers\Api\ApiController.php
<?php
namespace App\Controllers\Api;
use CodeIgniter\RESTful\ResourceController;
use App\Models\UsersModel;
class ApiController extends ResourceController
{
/**
* Return an array of resource objects, themselves in array format
*
* #return mixed
*/
public function index()
{
//
$users = new UsersModel();
$response = [
'status' => 200,
"error" => false,
'messages' => 'User list API',
'data' => $users->findAll()
];
return $this->respondCreated($response);
}
/**
* Create a new resource object, from "posted" parameters
*
* #return mixed
*/
public function create()
{
//
$rules = [
'first_name' => 'required|min_length[3]|max_length[20]',
'last_name' => 'required|min_length[3]|max_length[20]',
'email' => 'required|min_length[6]|max_length[50]|valid_email|is_unique[users.email]',
'password' => 'required|min_length[8]|max_length[255]',
'password_confirm' => 'matches[password]',
];
...
...
...
return $this->respondCreated($response);
}
}
Any help would be appreciated.

How to add worklog to Jira Issue using REST API (NodeJS)?

I am creating an add-on which should create worklogs automatically. I am using node-js (jira-connector).
I managed to get Issues, and to create new, but I am getting the error:
UnhandledPromiseRejectionWarning: Error: Missing 'worklog' property
when I want to add worklogs to a Issue
function updateIssueInJira()
{
var jira = getoAuth();
try {
return new Promise(() => {
jira.issue.addWorkLog({
opts: {
issueKey: 'NTS-4',
adjustEstimate: 'new',
newEstimade: '2d',
worklog: 'Testing'
}
})
});
} catch (error) {
console.log(error);
}
}
The definition of addWorkLog is:
/**
* Adds a new worklog entry to an issue.
*
* #method addWorkLog
* #memberOf IssueClient#
* #param {Object} opts The options to pass to the API. Note that this object must contain EITHER an issueId or
* issueKey property; issueId will be used over issueKey if both are present.
* #param {string} [opts.issueId] The id of the issue. EX: 10002
* #param {string} [opts.issueKey] The Key of the issue. EX: JWR-3
* #param {string} [opts.adjustEstimate] Allows you to provide specific instructions to update the remaining time
* estimate of the issue. Valid values are
* * "new" - sets the estimate to a specific value
* * "leave"- leaves the estimate as is
* * "manual" - specify a specific amount to increase remaining estimate by
* * "auto"- Default option. Will automatically adjust the value based on the
* new timeSpent specified on the worklog
* #param {string} [opts.newEstimate] (required when "new" is selected for adjustEstimate) the new value for the
* remaining estimate field. e.g. "2d"
* #param {string} [opts.reduceBy] (required when "manual" is selected for adjustEstimate) the amount to reduce the
* remaining estimate by e.g. "2d"
* #param {Object} opts.worklog See {#link: https://docs.atlassian.com/jira/REST/latest/#d2e1106}
* #param [callback] Called after the worklog is added.
* #return {P
romise} Resolved after the worklog is added.
*/
this.addWorkLog = function (opts, callback) {
if (!opts.worklog) {
throw new Error(errorStrings.NO_WORKLOG_ERROR);
}
var options = this.buildRequestOptions(opts, '/worklog', 'POST', opts.worklog, {
newEstimate: opts.newEstimate,
reduceBy: opts.reduceBy,
adjustEstimate: opts.adjustEstimate
});
return this.jiraClient.makeRequest(options, callback, 'Worklog Added');
};
Under getoAuth() I am doing my oAuth authentification, and I want to add the worklog to the Issue NTS-4.
I found a solution. I am sending the input directly via REST Call (POST). For that, I am using 'request'
function updateIssueInJira(oauth)
{
var testjson = {
author: {
emailAddress: "myemail"
},
comment: "Test",
timeSpentSeconds: "2700"
}
request.post({
url:'https://thelocation.com/rest/api/2/issue/ISSUEKEY/worklog/',
oauth:oauth,
json:true,
body: testjson
},
function (e, r, user) {
console.log(user)
});
}

Detect locale and alter url (redirect) to include locale

What i want to do is, to detect the language of a users browser and redirect him to a page containing the locale in url.
I thought, the easiest way would be, to register a kernel listener. So that is what i did:
services:
kernel__request_listener:
class: Me\MainBundle\Listener\KernelRequestListener
tags:
- { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
calls:
- [ setContainer, [ #service_container ] ]
KernelRequestListener.php
...
/**
* #Service
*/
class KernelRequestListener
{
/**
* #Observe("kernel.request")
*/
public function onKernelRequest( GetResponseEvent $response )
{
if( $newLocale = $this->newLocale() )
{
$parmArray = $request->get('_route_params');
$parmArray['_locale'] = $newLocale;
$redirectResponse = new RedirectResponse( $this->getContainer()->get('router')->generate($request->get('_route'), $parmArray) );
$redirectResponse->headers->setCookie( new Cookie('b_locale', $newLocale, time() + 2592000) );
$response->setResponse( $redirectResponse );
}
}
...
}
The method $this->newLocale() just detects if the user should be redirected to another language and returns the new language code (i.e. DE or FR).
Here comes the problem:
I am using assetics to compress the js files and jms/i18n-routing-bundle to do the locale-based routing. When the kernel listener switches locale, the page starts loading the js files over and over again. also, there are several pages (i.e. the profiler, login/logout etc.) where no redirect should take place as it makes no sense or breaks smthing.
Is a kernel listener the right place to do such a redirection or is there any better place. How to resolve the problems above?
Add, before your code:
public function onKernelRequest(GetResponseEvent $event)
{
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}
$request = $event->getRequest();
if ($request->getRequestFormat() !== 'html') {
return;
}
[CODE]

Drupal: Create custom search

I'm trying to create a custom search but getting stuck.
What I want is to have a dropdownbox so the user can choose where to search in.
These options can mean 1 or more content types.
So if he chooses options A, then the search will look in node-type P,Q,R.
But he may not give those results, but only the uid's which will be then themed to gather specific data for that user.
To make it a little bit clearer, Suppose I want to llok for people. The what I'm searching in is 2 content profile types. But ofcourse you dont want to display those as a result, but a nice picture of the user and some data.
I started with creating a form with a textfield and the dropdown box.
Then, in the submit handler, i created the keys and redirected to another pages with those keys as a tail. This page has been defined in the menu hook, just like how search does it.
After that I want to call hook_view to do the actual search by calling node_search, and give back the results.
Unfortunately, it goes wrong. When i click the Search button, it gives me a 404.
But am I on the right track? Is this the way to create a custom search?
Thx for your help.
Here's the code for some clarity:
<?php
// $Id$
/*
* #file
* Searches on Project, Person, Portfolio or Group.
*/
/**
* returns an array of menu items
* #return array of menu items
*/
function vm_search_menu() {
$subjects = _vm_search_get_subjects();
foreach ($subjects as $name => $description) {
$items['zoek/'. $name .'/%menu_tail'] = array(
'page callback' => 'vm_search_view',
'page arguments' => array($name),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
/**
* create a block to put the form into.
* #param $op
* #param $delta
* #param $edit
* #return mixed
*/
function vm_search_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks[0]['info'] = t('Algemene zoek');
return $blocks;
case 'view':
if (0 == $delta) {
$block['subject'] = t('');
$block['content'] = drupal_get_form('vm_search_general_form');
}
return $block;
}
}
/**
* Define the form.
*/
function vm_search_general_form() {
$subjects = _vm_search_get_subjects();
foreach ($subjects as $key => $subject) {
$options[$key] = $subject['desc'];
}
$form['subjects'] = array(
'#type' => 'select',
'#options' => $options,
'#required' => TRUE,
);
$form['keys'] = array(
'#type' => 'textfield',
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Zoek'),
);
return $form;
}
function vm_search_general_form_submit($form, &$form_state) {
$subjects = _vm_search_get_subjects();
$keys = $form_state['values']['keys']; //the search keys
//the content types to search in
$keys .= ' type:' . implode(',', $subjects[$form_state['values']['subjects']]['types']);
//redirect to the page, where vm_search_view will handle the actual search
$form_state['redirect'] = 'zoek/'. $form_state['values']['subjects'] .'/'. $keys;
}
/**
* Menu callback; presents the search results.
*/
function vm_search_view($type = 'node') {
// Search form submits with POST but redirects to GET. This way we can keep
// the search query URL clean as a whistle:
// search/type/keyword+keyword
if (!isset($_POST['form_id'])) {
if ($type == '') {
// Note: search/node can not be a default tab because it would take on the
// path of its parent (search). It would prevent remembering keywords when
// switching tabs. This is why we drupal_goto to it from the parent instead.
drupal_goto($front_page);
}
$keys = search_get_keys();
// Only perform search if there is non-whitespace search term:
$results = '';
if (trim($keys)) {
// Log the search keys:
watchdog('vm_search', '%keys (#type).', array('%keys' => $keys, '#type' => $type));
// Collect the search results:
$results = node_search('search', $type);
if ($results) {
$results = theme('box', t('Zoek resultaten'), $results);
}
else {
$results = theme('box', t('Je zoek heeft geen resultaten opgeleverd.'));
}
}
}
return $results;
}
/**
* returns array where to look for
* #return array
*/
function _vm_search_get_subjects() {
$subjects['opdracht'] =
array('desc' => t('Opdracht'),
'types' => array('project')
);
$subjects['persoon'] =
array('desc' => t('Persoon'),
'types' => array('types_specialisatie', 'smaak_en_interesses')
);
$subjects['groep'] =
array('desc' => t('Groep'),
'types' => array('Villamedia_groep')
);
$subjects['portfolio'] =
array('desc' => t('Portfolio'),
'types' => array('artikel')
);
return $subjects;
}
To be honest, I haven't seen many people implement hook_search. Most just use Views, or, for advanced things, something like Faceted Search.
Did you consider using either for your current project? Why didn't it work?
you could also use a combination of hook_menu for your results, and db_queries with your custom (and optimized so faster) queries.
For example:
search/%/%
where the arguments could be whatever you need, for example the first one for minimum price, the second price to the maximum price, third for minimal bedrooms... Your url would look always like that:
search/200/400/null/3/ ...
I have used a null, but it could be anything that you prefer to consider this field as empty.
Then, from your select form you have just to redirect following the structure of this url and adding the parameters in its correct place.
It is probalby not the most beautiful way of building a url, but using this technique and hook_theme will allow you to have an unlimited flexibility. I can show you a project where we are using this technique and, I think it looks pretty good :-).
Any comment regarding this would be much aprreciated :-).

Resources