1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: onysko |
5
|
|
|
* Date: 10.06.2015 |
6
|
|
|
* Time: 16:43 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace samsoncms\app\gallery\tab; |
10
|
|
|
|
11
|
|
|
use samson\activerecord\field; |
12
|
|
|
use samson\cms\Navigation; |
13
|
|
|
use samsoncms\form\tab\Generic; |
14
|
|
|
use samsonframework\core\RenderInterface; |
15
|
|
|
use samsonframework\orm\QueryInterface; |
16
|
|
|
use samsonframework\orm\Record; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* SamsonCMS material form gallery tab |
20
|
|
|
* @package samsoncms\app\gallery\tab |
21
|
|
|
*/ |
22
|
|
|
class Gallery extends Generic |
23
|
|
|
{ |
24
|
|
|
/** @var string Tab name or identifier */ |
25
|
|
|
protected $name = 'Галлерея'; |
26
|
|
|
|
27
|
|
|
/** @var string HTML tab identifier*/ |
28
|
|
|
protected $id = 'gallery_tab'; |
29
|
|
|
|
30
|
|
|
/** @var \samson\activerecord\materialfield Pointer to gallery additional field record */ |
31
|
|
|
public $materialField; |
32
|
|
|
|
33
|
|
|
/** @inheritdoc */ |
34
|
|
|
public function __construct(RenderInterface $renderer, QueryInterface $query, Record $entity, field $field) |
35
|
|
|
{ |
36
|
|
|
// Check if material have this gallery additional field stored |
37
|
|
|
if (!$query->className('materialfield') |
|
|
|
|
38
|
|
|
->cond('MaterialID', $entity->id) |
39
|
|
|
->cond('FieldID', $field->id) |
40
|
|
|
->first($this->materialField)) { |
41
|
|
|
// Create materialfield object |
42
|
|
|
$this->materialField = new \samson\activerecord\materialfield(false); |
|
|
|
|
43
|
|
|
$this->materialField->FieldID = $field->id; |
44
|
|
|
$this->materialField->MaterialID = $entity->id; |
45
|
|
|
$this->materialField->Active = 1; |
|
|
|
|
46
|
|
|
$this->materialField->save(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// Form tab name |
50
|
|
|
$this->name = t(isset($field->Name{0}) ? $field->Name : $this->name, true); |
|
|
|
|
51
|
|
|
|
52
|
|
|
// Call parent constructor to define all class fields |
53
|
|
|
parent::__construct($renderer, $query, $entity); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** @inheritdoc */ |
57
|
|
|
public function content() |
58
|
|
|
{ |
59
|
|
|
$content = $this->renderer->getHTML($this->materialField->id); |
|
|
|
|
60
|
|
|
|
61
|
|
|
return $this->renderer->view($this->contentView)->content($content)->output(); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: