Skip to content

Commit 3c84bc5

Browse files
committed
implement changes to address #228, updated
1 parent 276acb3 commit 3c84bc5

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Yii2 multiple input change log
77

88
2.15.1 (for review)
99
=======================
10-
- #228 added `fontMap` and `fontSource`property for MultipleInput and TabularInput
10+
- #228 added `iconMap` and `iconSource`property for MultipleInput and TabularInput
1111
- #228 changed the following methods to support icon class:
1212
BaseColumn->renderDragColumn(), TableRenderer->renderCellContent(), BaseRenderer->prepareButtons()
1313

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ Multiple input and Tabular input widgets now support FontAwesome and indeed any
158158

159159
To take advantage of this, please proceed as follows:
160160
1. Include the preferred icon library into your project. If you wish to use fontAwesome, you can use the included FontAwesomeAsset which will integrate the free fa from their CDN;
161-
2. Add a mapping for your preferred icon library if its not in the fontMap array of the widget, like the following;
161+
2. Add a mapping for your preferred icon library if its not in the iconMap array of the widget, like the following;
162162
```
163-
public $fontMap = [
163+
public $iconMap = [
164164
'glyphicons' => [
165165
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
166166
'remove' => 'glyphicon glyphicon-remove',
@@ -177,13 +177,13 @@ public $fontMap = [
177177
'drag-handle' => 'my my-bars',
178178
'remove' => 'my my-times',
179179
'add' => 'my my-plus',
180-
'clone' => 'my fa-files-o',
180+
'clone' => 'my my-files',
181181
]
182182
];
183183
```
184-
3. Set the preffered font source
184+
3. Set the preffered icon source
185185
```
186-
public $fontSource = 'my-amazing-icons';
186+
public $iconSource = 'my-amazing-icons';
187187
```
188188
If you do none of the above, the default behavior which assumes you are using glyphicons is retained.
189189

src/MultipleInput.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class MultipleInput extends InputWidget
164164
* @var array
165165
* --icon library classes mapped for various controls
166166
*/
167-
public $fontMap = [
167+
public $iconMap = [
168168
'glyphicons' => [
169169
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
170170
'remove' => 'glyphicon glyphicon-remove',
@@ -182,7 +182,7 @@ class MultipleInput extends InputWidget
182182
* @var string
183183
* --name of default icon library
184184
*/
185-
public $fontSource = 'glyphicons';
185+
public $iconSource = 'glyphicons';
186186

187187
/**
188188
* Initialization.
@@ -281,9 +281,9 @@ private function createRenderer()
281281
}
282282

283283
/**
284-
* set default font map
284+
* set default icon map
285285
*/
286-
$fontmap = array_key_exists($this->fontSource, $this->fontMap)?$this->fontMap[$this->fontSource]:$this->fontMap['glyphicons'];
286+
$iconmap = array_key_exists($this->iconSource, $this->iconMap) ? $this->iconMap[$this->iconSource] : $this->iconMap['glyphicons'];
287287
$config = [
288288
'id' => $this->getId(),
289289
'columns' => $this->columns,
@@ -301,7 +301,7 @@ private function createRenderer()
301301
'enableError' => $this->enableError,
302302
'cloneButton' => $this->cloneButton,
303303
'extraButtons' => $this->extraButtons,
304-
'fontMap' => $fontmap,
304+
'iconMap' => $iconmap,
305305
];
306306

307307
if ($this->removeButtonOptions !== null) {

src/TabularInput.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class TabularInput extends Widget
152152
* @var array
153153
* --icon library classes mapped for various controls
154154
*/
155-
public $fontMap = [
155+
public $iconMap = [
156156
'glyphicons' => [
157157
'drag-handle' => 'glyphicon glyphicon-menu-hamburger',
158158
'remove' => 'glyphicon glyphicon-remove',
@@ -170,7 +170,7 @@ class TabularInput extends Widget
170170
* @var string
171171
* --name of default icon library
172172
*/
173-
public $fontSource = 'glyphicons';
173+
public $iconSource = 'glyphicons';
174174

175175
/**
176176
* Initialization.
@@ -225,9 +225,9 @@ public function run()
225225
private function createRenderer()
226226
{
227227
/**
228-
* set default font map
228+
* set default icon map
229229
*/
230-
$fontmap = array_key_exists($this->fontSource, $this->fontMap)?$this->fontMap[$this->fontSource]:$this->fontMap['glyphicons'];
230+
$iconmap = array_key_exists($this->iconSource, $this->iconMap) ? $this->iconMap[$this->iconSource] : $this->iconMap['glyphicons'];
231231
$config = [
232232
'id' => $this->getId(),
233233
'columns' => $this->columns,
@@ -244,7 +244,7 @@ private function createRenderer()
244244
'sortable' => $this->sortable,
245245
'enableError' => $this->enableError,
246246
'layoutConfig' => $this->layoutConfig,
247-
'fontMap' => $fontmap,
247+
'iconMap' => $iconmap,
248248
];
249249

250250
if ($this->removeButtonOptions !== null) {

src/components/BaseColumn.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,6 @@ protected function renderStatic($name, $value, $options)
467467
*/
468468
protected function renderDragColumn($name, $value, $options)
469469
{
470-
// return Html::tag('span', null, ['class' => 'glyphicon glyphicon-menu-hamburger drag-handle']);
471470
/**
472471
* Class was passed into options by TableRenderer->renderCellContent(),
473472
* we can extract it here
@@ -478,7 +477,7 @@ protected function renderDragColumn($name, $value, $options)
478477
}
479478
$dragClass = implode(" ", [$class, 'drag-handle']);
480479

481-
return Html::tag('span', null, ['class'=>$dragClass]);
480+
return Html::tag('span', null, ['class' => $dragClass]);
482481
}
483482

484483
/**

src/renderers/BaseRenderer.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ abstract class BaseRenderer extends BaseObject implements RendererInterface
166166
*/
167167
public $layoutConfig = [];
168168

169-
public $fontMap;
169+
public $iconMap;
170170

171171
/**
172172
* @inheritdoc
@@ -250,23 +250,23 @@ private function prepareButtons()
250250
}
251251

252252
if (!array_key_exists('label', $this->removeButtonOptions)) {
253-
$this->removeButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getFontClass('remove')]);
253+
$this->removeButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getIconClass('remove')]);
254254
}
255255

256256
if (!array_key_exists('class', $this->addButtonOptions)) {
257257
$this->addButtonOptions['class'] = 'btn btn-default';
258258
}
259259

260260
if (!array_key_exists('label', $this->addButtonOptions)) {
261-
$this->addButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getFontClass('add')]);
261+
$this->addButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getIconClass('add')]);
262262
}
263263

264264
if (!array_key_exists('class', $this->cloneButtonOptions)) {
265265
$this->cloneButtonOptions['class'] = 'btn btn-info';
266266
}
267267

268268
if (!array_key_exists('label', $this->cloneButtonOptions)) {
269-
$this->cloneButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getFontClass('clone')]);
269+
$this->cloneButtonOptions['label'] = Html::tag('i', null, ['class' => $this->getIconClass('clone')]);
270270
}
271271
}
272272

@@ -496,9 +496,13 @@ protected function prepareJsAttributes()
496496
* @param $action - the control parameter, used as key into allowed types
497497
* @return string - the relevant icon class
498498
*/
499-
protected function getFontClass($action) {
499+
protected function getIconClass($action) {
500500
if (in_array($action, ['add', 'remove', 'clone', 'drag-handle'])) {
501-
return $this->fontMap[$action];
501+
return $this->iconMap[$action];
502+
}
503+
504+
if (YII_DEBUG) {
505+
throw new InvalidConfigException('Out of bounds, "' . $action . '" not found in your iconMap');
502506
}
503507
return '';
504508
}

src/renderers/TableRenderer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ public function renderCellContent($column, $index)
255255
$name = $column->getElementName($index);
256256

257257
/**
258-
* This class inherits fontMap from BaseRenderer
258+
* This class inherits iconMap from BaseRenderer
259259
* If the input to be rendered is a drag column, we give it the appropriate icon class
260260
* via the $options array
261261
*/
262262
$options = ['id' => $id];
263-
if (substr($id, -4)=='drag') {
264-
$options = ArrayHelper::merge($options, ['class'=>$this->fontMap['drag-handle']]);
263+
if (substr($id, -4) === 'drag') {
264+
$options = ArrayHelper::merge($options, ['class' => $this->iconMap['drag-handle']]);
265265
}
266266
$input = $column->renderInput($name, $options);
267267

0 commit comments

Comments
 (0)