Passed
Push — master ( 154e9f...c95a25 )
by Aimeos
03:44
created

Standard::delete()   B

Complexity

Conditions 6
Paths 46

Size

Total Lines 51
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 29
nc 46
nop 0
dl 0
loc 51
rs 8.8337
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 * @package Admin
7
 * @subpackage JQAdm
8
 */
9
10
11
namespace Aimeos\Admin\JQAdm\Plugin;
12
13
sprintf( 'plugin' ); // for translation
14
15
16
/**
17
 * Default implementation of plugin JQAdm client.
18
 *
19
 * @package Admin
20
 * @subpackage JQAdm
21
 */
22
class Standard
23
	extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base
24
	implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface
25
{
26
	/**
27
	 * Copies a resource
28
	 *
29
	 * @return string HTML output
30
	 */
31
	public function copy()
32
	{
33
		$view = $this->getView();
34
		$context = $this->getContext();
35
36
		try
37
		{
38
			if( ( $id = $view->param( 'id' ) ) === null ) {
39
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
40
			}
41
42
			$manager = \Aimeos\MShop::create( $context, 'plugin' );
43
44
			$view->item = $manager->getItem( $id );
45
			$view->itemData = $this->toArray( $view->item, true );
46
			$view->itemSubparts = $this->getSubClientNames();
47
			$view->itemProviders = $this->getProviderNames();
48
			$view->itemDecorators = $this->getDecoratorNames();
49
			$view->itemAttributes = $this->getConfigAttributes( $view->item );
50
			$view->itemTypes = $this->getTypeItems();
51
			$view->itemBody = '';
52
53
			foreach( $this->getSubClients() as $idx => $client )
54
			{
55
				$view->tabindex = ++$idx + 1;
56
				$view->itemBody .= $client->copy();
57
			}
58
		}
59
		catch( \Aimeos\MShop\Exception $e )
60
		{
61
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
62
			$view->errors = $view->get( 'errors', [] ) + $error;
63
			$this->logException( $e );
64
		}
65
		catch( \Exception $e )
66
		{
67
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
68
			$view->errors = $view->get( 'errors', [] ) + $error;
69
			$this->logException( $e );
70
		}
71
72
		return $this->render( $view );
73
	}
74
75
76
	/**
77
	 * Creates a new resource
78
	 *
79
	 * @return string HTML output
80
	 */
81
	public function create()
82
	{
83
		$view = $this->getView();
84
		$context = $this->getContext();
85
86
		try
87
		{
88
			$data = $view->param( 'item', [] );
89
90
			if( !isset( $view->item ) ) {
91
				$view->item = \Aimeos\MShop::create( $context, 'plugin' )->createItem();
92
			}
93
94
			$data['plugin.siteid'] = $view->item->getSiteId();
95
96
			$view->itemSubparts = $this->getSubClientNames();
97
			$view->itemDecorators = $this->getDecoratorNames();
98
			$view->itemProviders = $this->getProviderNames();
99
			$view->itemTypes = $this->getTypeItems();
100
			$view->itemData = $data;
101
			$view->itemBody = '';
102
103
			foreach( $this->getSubClients() as $idx => $client )
104
			{
105
				$view->tabindex = ++$idx + 1;
106
				$view->itemBody .= $client->create();
107
			}
108
		}
109
		catch( \Aimeos\MShop\Exception $e )
110
		{
111
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
112
			$view->errors = $view->get( 'errors', [] ) + $error;
113
			$this->logException( $e );
114
		}
115
		catch( \Exception $e )
116
		{
117
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
118
			$view->errors = $view->get( 'errors', [] ) + $error;
119
			$this->logException( $e );
120
		}
121
122
		return $this->render( $view );
123
	}
124
125
126
	/**
127
	 * Deletes a resource
128
	 *
129
	 * @return string|null HTML output
130
	 */
131
	public function delete()
132
	{
133
		$view = $this->getView();
134
		$context = $this->getContext();
135
136
		$manager = \Aimeos\MShop::create( $context, 'plugin' );
137
		$manager->begin();
138
139
		try
140
		{
141
			if( ( $ids = $view->param( 'id' ) ) === null ) {
142
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
143
			}
144
145
			$search = $manager->createSearch()->setSlice( 0, count( (array) $ids ) );
146
			$search->setConditions( $search->compare( '==', 'plugin.id', $ids ) );
147
			$items = $manager->searchItems( $search );
148
149
			foreach( $items as $item )
150
			{
151
				$view->item = $item;
152
153
				foreach( $this->getSubClients() as $client ) {
154
					$client->delete();
155
				}
156
157
				$manager->saveItem( $view->item );
158
			}
159
160
			$manager->deleteItems( array_keys( $items ) );
161
			$manager->commit();
162
163
			$this->nextAction( $view, 'search', 'plugin', null, 'delete' );
164
			return;
165
		}
166
		catch( \Aimeos\MShop\Exception $e )
167
		{
168
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
169
			$view->errors = $view->get( 'errors', [] ) + $error;
170
			$this->logException( $e );
171
		}
172
		catch( \Exception $e )
173
		{
174
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
175
			$view->errors = $view->get( 'errors', [] ) + $error;
176
			$this->logException( $e );
177
		}
178
179
		$manager->rollback();
180
181
		return $this->search();
182
	}
183
184
185
	/**
186
	 * Returns a single resource
187
	 *
188
	 * @return string HTML output
189
	 */
190
	public function get()
191
	{
192
		$view = $this->getView();
193
		$context = $this->getContext();
194
195
		try
196
		{
197
			if( ( $id = $view->param( 'id' ) ) === null ) {
198
				throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Required parameter "%1$s" is missing', 'id' ) );
199
			}
200
201
			$manager = \Aimeos\MShop::create( $context, 'plugin' );
202
203
			$view->item = $manager->getItem( $id );
204
			$view->itemData = $this->toArray( $view->item );
205
			$view->itemSubparts = $this->getSubClientNames();
206
			$view->itemDecorators = $this->getDecoratorNames();
207
			$view->itemProviders = $this->getProviderNames();
208
			$view->itemAttributes = $this->getConfigAttributes( $view->item );
209
			$view->itemTypes = $this->getTypeItems();
210
			$view->itemBody = '';
211
212
			foreach( $this->getSubClients() as $idx => $client )
213
			{
214
				$view->tabindex = ++$idx + 1;
215
				$view->itemBody .= $client->get();
216
			}
217
		}
218
		catch( \Aimeos\MShop\Exception $e )
219
		{
220
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
221
			$view->errors = $view->get( 'errors', [] ) + $error;
222
			$this->logException( $e );
223
		}
224
		catch( \Exception $e )
225
		{
226
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
227
			$view->errors = $view->get( 'errors', [] ) + $error;
228
			$this->logException( $e );
229
		}
230
231
		return $this->render( $view );
232
	}
233
234
235
	/**
236
	 * Saves the data
237
	 *
238
	 * @return string HTML output
239
	 */
240
	public function save()
241
	{
242
		$view = $this->getView();
243
		$context = $this->getContext();
244
245
		$manager = \Aimeos\MShop::create( $context, 'plugin' );
246
		$manager->begin();
247
248
		try
249
		{
250
			$item = $this->fromArray( $view->param( 'item', [] ) );
251
			$view->item = $item->getId() ? $item : $manager->saveItem( $item );
252
			$view->itemBody = '';
253
254
			foreach( $this->getSubClients() as $client ) {
255
				$view->itemBody .= $client->save();
256
			}
257
258
			$manager->saveItem( clone $view->item );
259
			$manager->commit();
260
261
			$this->nextAction( $view, $view->param( 'next' ), 'plugin', $view->item->getId(), 'save' );
262
			return;
263
		}
264
		catch( \Aimeos\Admin\JQAdm\Exception $e )
265
		{
266
			// fall through to create
267
		}
268
		catch( \Aimeos\MShop\Exception $e )
269
		{
270
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
271
			$view->errors = $view->get( 'errors', [] ) + $error;
272
			$this->logException( $e );
273
		}
274
		catch( \Exception $e )
275
		{
276
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
277
			$view->errors = $view->get( 'errors', [] ) + $error;
278
			$this->logException( $e );
279
		}
280
281
		$manager->rollback();
282
283
		return $this->create();
284
	}
285
286
287
	/**
288
	 * Returns a list of resource according to the conditions
289
	 *
290
	 * @return string HTML output
291
	 */
292
	public function search()
293
	{
294
		$view = $this->getView();
295
		$context = $this->getContext();
296
297
		try
298
		{
299
			$total = 0;
300
			$params = $this->storeSearchParams( $view->param(), 'plugin' );
301
			$manager = \Aimeos\MShop::create( $context, 'plugin' );
302
303
			$search = $manager->createSearch();
304
			$search->setSortations( [$search->sort( '+', 'plugin.type' ), $search->sort( '+', 'plugin.position' )] );
305
			$search = $this->initCriteria( $search, $params );
306
307
			$view->items = $manager->searchItems( $search, [], $total );
308
			$view->filterAttributes = $manager->getSearchAttributes( true );
309
			$view->filterOperators = $search->getOperators();
310
			$view->itemTypes = $this->getTypeItems();
311
			$view->total = $total;
312
			$view->itemBody = '';
313
314
			foreach( $this->getSubClients() as $client ) {
315
				$view->itemBody .= $client->search();
316
			}
317
		}
318
		catch( \Aimeos\MShop\Exception $e )
319
		{
320
			$error = array( 'plugin-item' => $context->getI18n()->dt( 'mshop', $e->getMessage() ) );
321
			$view->errors = $view->get( 'errors', [] ) + $error;
322
			$this->logException( $e );
323
		}
324
		catch( \Exception $e )
325
		{
326
			$error = array( 'plugin-item' => $e->getMessage() . ', ' . $e->getFile() . ':' . $e->getLine() );
327
			$view->errors = $view->get( 'errors', [] ) + $error;
328
			$this->logException( $e );
329
		}
330
331
		/** admin/jqadm/plugin/template-list
332
		 * Relative path to the HTML body template for the plugin list.
333
		 *
334
		 * The template file contains the HTML code and processing instructions
335
		 * to generate the result shown in the body of the frontend. The
336
		 * configuration string is the path to the template file relative
337
		 * to the templates directory (usually in admin/jqadm/templates).
338
		 *
339
		 * You can overwrite the template file configuration in extensions and
340
		 * provide alternative templates. These alternative templates should be
341
		 * named like the default one but with the string "default" replaced by
342
		 * an unique name. You may use the name of your project for this. If
343
		 * you've implemented an alternative client class as well, "default"
344
		 * should be replaced by the name of the new class.
345
		 *
346
		 * @param string Relative path to the template creating the HTML code
347
		 * @since 2016.04
348
		 * @category Developer
349
		 */
350
		$tplconf = 'admin/jqadm/plugin/template-list';
351
		$default = 'plugin/list-standard';
352
353
		return $view->render( $view->config( $tplconf, $default ) );
354
	}
355
356
357
	/**
358
	 * Returns the sub-client given by its name.
359
	 *
360
	 * @param string $type Name of the client type
361
	 * @param string|null $name Name of the sub-client (Default if null)
362
	 * @return \Aimeos\Admin\JQAdm\Iface Sub-client object
363
	 */
364
	public function getSubClient( $type, $name = null )
365
	{
366
		/** admin/jqadm/plugin/decorators/excludes
367
		 * Excludes decorators added by the "common" option from the plugin JQAdm client
368
		 *
369
		 * Decorators extend the functionality of a class by adding new aspects
370
		 * (e.g. log what is currently done), executing the methods of the underlying
371
		 * class only in certain conditions (e.g. only for logged in users) or
372
		 * modify what is returned to the caller.
373
		 *
374
		 * This option allows you to remove a decorator added via
375
		 * "client/jqadm/common/decorators/default" before they are wrapped
376
		 * around the JQAdm client.
377
		 *
378
		 *  admin/jqadm/plugin/decorators/excludes = array( 'decorator1' )
379
		 *
380
		 * This would remove the decorator named "decorator1" from the list of
381
		 * common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via
382
		 * "client/jqadm/common/decorators/default" to the JQAdm client.
383
		 *
384
		 * @param array List of decorator names
385
		 * @since 2017.10
386
		 * @category Developer
387
		 * @see admin/jqadm/common/decorators/default
388
		 * @see admin/jqadm/plugin/decorators/global
389
		 * @see admin/jqadm/plugin/decorators/local
390
		 */
391
392
		/** admin/jqadm/plugin/decorators/global
393
		 * Adds a list of globally available decorators only to the plugin JQAdm client
394
		 *
395
		 * Decorators extend the functionality of a class by adding new aspects
396
		 * (e.g. log what is currently done), executing the methods of the underlying
397
		 * class only in certain conditions (e.g. only for logged in users) or
398
		 * modify what is returned to the caller.
399
		 *
400
		 * This option allows you to wrap global decorators
401
		 * ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client.
402
		 *
403
		 *  admin/jqadm/plugin/decorators/global = array( 'decorator1' )
404
		 *
405
		 * This would add the decorator named "decorator1" defined by
406
		 * "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client.
407
		 *
408
		 * @param array List of decorator names
409
		 * @since 2017.10
410
		 * @category Developer
411
		 * @see admin/jqadm/common/decorators/default
412
		 * @see admin/jqadm/plugin/decorators/excludes
413
		 * @see admin/jqadm/plugin/decorators/local
414
		 */
415
416
		/** admin/jqadm/plugin/decorators/local
417
		 * Adds a list of local decorators only to the plugin JQAdm client
418
		 *
419
		 * Decorators extend the functionality of a class by adding new aspects
420
		 * (e.g. log what is currently done), executing the methods of the underlying
421
		 * class only in certain conditions (e.g. only for logged in users) or
422
		 * modify what is returned to the caller.
423
		 *
424
		 * This option allows you to wrap local decorators
425
		 * ("\Aimeos\Admin\JQAdm\Plugin\Decorator\*") around the JQAdm client.
426
		 *
427
		 *  admin/jqadm/plugin/decorators/local = array( 'decorator2' )
428
		 *
429
		 * This would add the decorator named "decorator2" defined by
430
		 * "\Aimeos\Admin\JQAdm\Plugin\Decorator\Decorator2" only to the JQAdm client.
431
		 *
432
		 * @param array List of decorator names
433
		 * @since 2017.10
434
		 * @category Developer
435
		 * @see admin/jqadm/common/decorators/default
436
		 * @see admin/jqadm/plugin/decorators/excludes
437
		 * @see admin/jqadm/plugin/decorators/global
438
		 */
439
		return $this->createSubClient( 'plugin/' . $type, $name );
440
	}
441
442
443
	/**
444
	 * Returns the backend configuration attributes of the provider and decorators
445
	 *
446
	 * @param \Aimeos\MShop\Plugin\Item\Iface $item Plugin item incl. provider/decorator property
447
	 * @return \Aimeos\MW\Common\Critera\Attribute\Iface[] List of configuration attributes
448
	 */
449
	public function getConfigAttributes( \Aimeos\MShop\Plugin\Item\Iface $item )
450
	{
451
		$manager = \Aimeos\MShop::create( $this->getContext(), 'plugin' );
452
453
		try {
454
			return $manager->getProvider( $item, $item->getType() )->getConfigBE();
455
		} catch( \Aimeos\MShop\Exception $e ) {
456
			return [];
457
		}
458
	}
459
460
461
	/**
462
	 * Returns the names of the available plugin decorators
463
	 *
464
	 * @return string[] List of decorator class names
465
	 */
466
	protected function getDecoratorNames()
467
	{
468
		$ds = DIRECTORY_SEPARATOR;
469
		return $this->getClassNames( 'MShop' . $ds . 'Plugin' . $ds . 'Provider' . $ds . 'Decorator' );
470
	}
471
472
473
	/**
474
	 * Returns the names of the available plugin providers
475
	 *
476
	 * @return string[] List of provider class names
477
	 */
478
	protected function getProviderNames()
479
	{
480
		$ds = DIRECTORY_SEPARATOR;
481
		return [
482
			'order' => $this->getClassNames( 'MShop' . $ds . 'Plugin' . $ds . 'Provider' . $ds . 'Order' )
483
		];
484
	}
485
486
487
	/**
488
	 * Returns the list of sub-client names configured for the client.
489
	 *
490
	 * @return array List of JQAdm client names
491
	 */
492
	protected function getSubClientNames()
493
	{
494
		/** admin/jqadm/plugin/standard/subparts
495
		 * List of JQAdm sub-clients rendered within the plugin section
496
		 *
497
		 * The output of the frontend is composed of the code generated by the JQAdm
498
		 * clients. Each JQAdm client can consist of serveral (or none) sub-clients
499
		 * that are responsible for rendering certain sub-parts of the output. The
500
		 * sub-clients can contain JQAdm clients themselves and therefore a
501
		 * hierarchical tree of JQAdm clients is composed. Each JQAdm client creates
502
		 * the output that is placed inside the container of its parent.
503
		 *
504
		 * At first, always the JQAdm code generated by the parent is printed, then
505
		 * the JQAdm code of its sub-clients. The order of the JQAdm sub-clients
506
		 * determines the order of the output of these sub-clients inside the parent
507
		 * container. If the configured list of clients is
508
		 *
509
		 *  array( "subclient1", "subclient2" )
510
		 *
511
		 * you can easily change the order of the output by reordering the subparts:
512
		 *
513
		 *  admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" )
514
		 *
515
		 * You can also remove one or more parts if they shouldn't be rendered:
516
		 *
517
		 *  admin/jqadm/<clients>/subparts = array( "subclient1" )
518
		 *
519
		 * As the clients only generates structural JQAdm, the layout defined via CSS
520
		 * should support adding, removing or reordering content by a fluid like
521
		 * design.
522
		 *
523
		 * @param array List of sub-client names
524
		 * @since 2017.10
525
		 * @category Developer
526
		 */
527
		return $this->getContext()->getConfig()->get( 'admin/jqadm/plugin/standard/subparts', [] );
528
	}
529
530
531
	/**
532
	 * Returns the available plugin type items
533
	 *
534
	 * @return array List of item implementing \Aimeos\MShop\Common\Type\Iface
535
	 */
536
	protected function getTypeItems()
537
	{
538
		$typeManager = \Aimeos\MShop::create( $this->getContext(), 'plugin/type' );
539
540
		$search = $typeManager->createSearch( true )->setSlice( 0, 10000 );
541
		$search->setSortations( [$search->sort( '+', 'plugin.type.position' )] );
542
543
		return $this->map( $typeManager->searchItems( $search ) );
544
	}
545
546
547
	/**
548
	 * Creates new and updates existing items using the data array
549
	 *
550
	 * @param array $data Data array
551
	 * @return \Aimeos\MShop\Plugin\Item\Iface New plugin item object
552
	 */
553
	protected function fromArray( array $data )
554
	{
555
		$conf = [];
556
557
		if( isset( $data['config']['key'] ) )
558
		{
559
			foreach( (array) $data['config']['key'] as $idx => $key )
560
			{
561
				if( trim( $key ) !== '' && isset( $data['config']['val'][$idx] ) )
562
				{
563
					if( ( $val = json_decode( $data['config']['val'][$idx] ) ) === null ) {
564
						$conf[$key] = $data['config']['val'][$idx];
565
					} else {
566
						$conf[$key] = $val;
567
					}
568
				}
569
			}
570
		}
571
572
		$manager = \Aimeos\MShop::create( $this->getContext(), 'plugin' );
573
574
		if( isset( $data['plugin.id'] ) && $data['plugin.id'] != '' ) {
575
			$item = $manager->getItem( $data['plugin.id'] );
576
		} else {
577
			$item = $manager->createItem();
578
		}
579
580
		$item->fromArray( $data, true );
581
		$item->setConfig( $conf );
0 ignored issues
show
Bug introduced by
The method setConfig() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Product\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

581
		$item->/** @scrutinizer ignore-call */ 
582
         setConfig( $conf );
Loading history...
Bug introduced by
The method setConfig() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

581
		$item->/** @scrutinizer ignore-call */ 
582
         setConfig( $conf );

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
582
583
		return $item;
584
	}
585
586
587
	/**
588
	 * Constructs the data array for the view from the given item
589
	 *
590
	 * @param \Aimeos\MShop\Plugin\Item\Iface $item Plugin item object
591
	 * @return string[] Multi-dimensional associative list of item data
592
	 */
593
	protected function toArray( \Aimeos\MShop\Plugin\Item\Iface $item, $copy = false )
594
	{
595
		$config = $item->getConfig();
596
		$data = $item->toArray( true );
597
		$data['config'] = [];
598
599
		if( $copy === true )
600
		{
601
			$data['plugin.siteid'] = $this->getContext()->getLocale()->getSiteId();
602
			$data['plugin.id'] = '';
603
		}
604
605
		ksort( $config );
606
607
		foreach( $config as $key => $value )
608
		{
609
			$data['config']['key'][] = $key;
610
			$data['config']['val'][] = $value;
611
		}
612
613
		return $data;
614
	}
615
616
617
	/**
618
	 * Returns the rendered template including the view data
619
	 *
620
	 * @param \Aimeos\MW\View\Iface $view View object with data assigned
621
	 * @return string HTML output
622
	 */
623
	protected function render( \Aimeos\MW\View\Iface $view )
624
	{
625
		/** admin/jqadm/plugin/template-item
626
		 * Relative path to the HTML body template for the plugin item.
627
		 *
628
		 * The template file contains the HTML code and processing instructions
629
		 * to generate the result shown in the body of the frontend. The
630
		 * configuration string is the path to the template file relative
631
		 * to the templates directory (usually in admin/jqadm/templates).
632
		 *
633
		 * You can overwrite the template file configuration in extensions and
634
		 * provide alternative templates. These alternative templates should be
635
		 * named like the default one but with the string "default" replaced by
636
		 * an unique name. You may use the name of your project for this. If
637
		 * you've implemented an alternative client class as well, "default"
638
		 * should be replaced by the name of the new class.
639
		 *
640
		 * @param string Relative path to the template creating the HTML code
641
		 * @since 2016.04
642
		 * @category Developer
643
		 */
644
		$tplconf = 'admin/jqadm/plugin/template-item';
645
		$default = 'plugin/item-standard';
646
647
		return $view->render( $view->config( $tplconf, $default ) );
648
	}
649
}
650