Projet

Général

Profil

Révision ed9a13f1

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/includes/FeedsConfigurable.inc
12 12
}
13 13

  
14 14
/**
15
 * Base class for configurable classes. Captures configuration handling, form
16
 * handling and distinguishes between in-memory configuration and persistent
17
 * configuration.
15
 * Base class for configurable classes.
16
 *
17
 * Captures configuration handling, form handling and distinguishes between
18
 * in-memory configuration and persistent configuration.
18 19
 *
19 20
 * Due to the magic method __get(), protected properties from this class and
20 21
 * from classes that extend this class will be publicly readable (but not
......
22 23
 */
23 24
abstract class FeedsConfigurable {
24 25

  
25
  // Holds the actual configuration information.
26
  /**
27
   * Holds the actual configuration information.
28
   *
29
   * @var array
30
   */
26 31
  protected $config;
27 32

  
28
  // A unique identifier for the configuration.
33
  /**
34
   * An unique identifier for the configuration.
35
   *
36
   * @var string
37
   */
29 38
  protected $id;
30 39

  
31
  /*
32
  CTools export type of this object.
33

  
34
  @todo Should live in FeedsImporter. Not all child classes
35
  of FeedsConfigurable are exportable. Same goes for $disabled.
36

  
37
  Export type can be one of
38
  FEEDS_EXPORT_NONE - the configurable only exists in memory
39
  EXPORT_IN_DATABASE - the configurable is defined in the database.
40
  EXPORT_IN_CODE - the configurable is defined in code.
41
  EXPORT_IN_CODE | EXPORT_IN_DATABASE - the configurable is defined in code, but
42
                                        overridden in the database.*/
40
  /**
41
   * CTools export type of this object.
42
   *
43
   * Export type can be one of:
44
   * - FEEDS_EXPORT_NONE - the configurable only exists in memory.
45
   * - EXPORT_IN_DATABASE - the configurable is defined in the database.
46
   * - EXPORT_IN_CODE - the configurable is defined in code.
47
   * - EXPORT_IN_CODE | EXPORT_IN_DATABASE - the configurable is defined in
48
   *   code, but overridden in the database.
49
   *
50
   * @var int
51
   *
52
   * @todo Should live in FeedsImporter. Not all child classes
53
   * of FeedsConfigurable are exportable. Same goes for $disabled.
54
   */
43 55
  protected $export_type;
44 56

  
45 57
  /**
46 58
   * CTools export enabled status of this object.
59
   *
60
   * @var bool
47 61
   */
48 62
  protected $disabled;
49 63

  
50 64
  /**
51
   * Instantiates a FeedsConfigurable object.
65
   * Provides a statically cached instance of a FeedsConfigurable subclass.
52 66
   *
53 67
   * Don't use directly, use feeds_importer() or feeds_plugin() instead.
54 68
   *
69
   * @param string $class
70
   *   The name of a subclass of FeedsConfigurable.
71
   * @param string $id
72
   *   The ID of this configuration object.
73
   *
74
   * @return FeedsConfigurable
75
   *   An instance of this class.
76
   *
77
   * @throws InvalidArgumentException
78
   *   When an empty configuration identifier is passed.
79
   *
55 80
   * @see feeds_importer()
56 81
   * @see feeds_plugin()
57 82
   */
58 83
  public static function instance($class, $id) {
84
    // @todo Verify that $class is an existing subclass of FeedsConfigurable.
59 85
    if (!strlen($id)) {
60 86
      throw new InvalidArgumentException(t('Empty configuration identifier.'));
61 87
    }
......
70 96

  
71 97
  /**
72 98
   * Constructor, set id and load default configuration.
99
   *
100
   * @param string $id
101
   *   The ID of this configuration object.
73 102
   */
74 103
  protected function __construct($id) {
75 104
    // Set this object's id.
......
112 141
  }
113 142

  
114 143
  /**
115
   * Determine whether this object is persistent and enabled. I. e. it is
116
   * defined either in code or in the database and it is enabled.
144
   * Determines whether this object is persistent and enabled.
145
   *
146
   * This means that it exists either in code or in the database and it is
147
   * enabled.
148
   *
149
   * @return $this
150
   *
151
   * @throws FeedsNotExistingException
152
   *   When the object is not persistent or is not enabled.
117 153
   */
118 154
  public function existing() {
119 155
    if (!$this->doesExist()) {
......
126 162
  }
127 163

  
128 164
  /**
129
   * Save a configuration. Concrete extending classes must implement a save
130
   * operation.
165
   * Saves a configuration.
166
   *
167
   * Concrete extending classes must implement a save operation.
131 168
   */
132
  public abstract function save();
169
  abstract public function save();
133 170

  
134 171
  /**
135 172
   * Copy a configuration.
173
   *
174
   * @param FeedsConfigurable $configurable
175
   *   The FeedsConfigurable instance to take the configuration from.
136 176
   */
137 177
  public function copy(FeedsConfigurable $configurable) {
138 178
    $this->setConfig($configurable->config);
......
141 181
  /**
142 182
   * Set configuration.
143 183
   *
144
   * @param $config
184
   * @param array $config
145 185
   *   Array containing configuration information. Config array will be filtered
146 186
   *   by the keys returned by configDefaults() and populated with default
147 187
   *   values that are not included in $config.
......
154 194
  /**
155 195
   * Similar to setConfig but adds to existing configuration.
156 196
   *
157
   * @param $config
197
   * @param array $config
158 198
   *   Array containing configuration information. Will be filtered by the keys
159 199
   *   returned by configDefaults().
160 200
   */
......
183 223
  /**
184 224
   * Implements getConfig().
185 225
   *
186
   * Return configuration array, ensure that all default values are present.
226
   * Returns configuration array, ensure that all default values are present.
227
   *
228
   * @return array
229
   *   The configuration for this object.
187 230
   */
188 231
  public function getConfig() {
189 232
    $defaults = $this->configDefaults();
......
225 268
  }
226 269

  
227 270
  /**
228
   * Return configuration form for this object. The keys of the configuration
229
   * form must match the keys of the array returned by configDefaults().
271
   * Returns configuration form for this object.
272
   *
273
   * The keys of the configuration form must match the keys of the array
274
   * returned by configDefaults().
275
   *
276
   * @param array $form_state
277
   *   The current state of the form.
230 278
   *
231
   * @return
279
   * @return array
232 280
   *   FormAPI style form definition.
233 281
   */
234 282
  public function configForm(&$form_state) {
......
240 288
   *
241 289
   * Set errors with form_set_error().
242 290
   *
243
   * @param $values
291
   * @param array $values
244 292
   *   An array that contains the values entered by the user through configForm.
245 293
   */
246 294
  public function configFormValidate(&$values) {
247 295
  }
248 296

  
249 297
  /**
250
   *  Submission handler for configForm().
298
   * Submission handler for configForm().
251 299
   *
252
   *  @param $values
300
   * @param array $values
301
   *   An array that contains the values entered by the user through configForm.
253 302
   */
254 303
  public function configFormSubmit(&$values) {
255 304
    $this->addConfig($values);
......
267 316
  public function dependencies() {
268 317
    return array();
269 318
  }
319

  
270 320
}
271 321

  
272 322
/**
273
 * Config form wrapper. Use to render the configuration form of
274
 * a FeedsConfigurable object.
323
 * FeedsConfigurable config form wrapper.
275 324
 *
276
 * @param $configurable
277
 *   FeedsConfigurable object.
278
 * @param $form_method
325
 * Used to render the configuration form of a FeedsConfigurable object.
326
 *
327
 * @param FeedsConfigurable $configurable
328
 *   The FeedsConfigurable instance for which a configuration form must be
329
 *   rendered.
330
 * @param string $form_method
279 331
 *   The form method that should be rendered.
280 332
 *
281
 * @return
333
 * @return array|null
282 334
 *   Config form array if available. NULL otherwise.
283 335
 */
284
function feeds_get_form($configurable, $form_method) {
336
function feeds_get_form(FeedsConfigurable $configurable, $form_method) {
285 337
  if (method_exists($configurable, $form_method)) {
286 338
    return drupal_get_form(get_class($configurable) . '_feeds_form', $configurable, $form_method);
287 339
  }
288 340
}
289 341

  
290 342
/**
291
 * Config form callback. Don't call directly, but use
343
 * Form constructor for a Feeds configuration form.
344
 *
345
 * Don't call directly, but use
292 346
 * feeds_get_form($configurable, 'method') instead.
293 347
 *
294
 * @param
295
 *   FormAPI $form_state.
296
 * @param
297
 *   FeedsConfigurable object.
298
 * @param
348
 * @param array $form
349
 *   The form.
350
 * @param array $form_state
351
 *   The current state of the form.
352
 * @param FeedsConfigurable $configurable
299 353
 *   The object to perform the save() operation on.
300
 * @param $form_method
354
 * @param string $form_method
301 355
 *   The $form_method that should be rendered.
356
 *
357
 * @return array
358
 *   Form array.
302 359
 */
303
function feeds_form($form, &$form_state, $configurable, $form_method) {
360
function feeds_form(array $form, array &$form_state, FeedsConfigurable $configurable, $form_method) {
304 361
  $form = $configurable->$form_method($form_state);
305 362
  $form['#configurable'] = $configurable;
306 363
  $form['#feeds_form_method'] = $form_method;
......
315 372
}
316 373

  
317 374
/**
318
 * Validation handler for feeds_form().
375
 * Form validation handler for feeds_form().
376
 *
377
 * @see feeds_form()
319 378
 */
320 379
function feeds_form_validate($form, &$form_state) {
321 380
  _feeds_form_helper($form, $form_state, 'Validate');
......
323 382

  
324 383
/**
325 384
 * Submit handler for feeds_form().
385
 *
386
 * @see feeds_form()
326 387
 */
327 388
function feeds_form_submit($form, &$form_state) {
328 389
  _feeds_form_helper($form, $form_state, 'Submit');
......
331 392
/**
332 393
 * Helper for Feeds validate and submit callbacks.
333 394
 *
395
 * @param array $form
396
 *   The form.
397
 * @param array $form_state
398
 *   The current state of the form.
399
 * @param string $action
400
 *   The action to perform on the form, for example:
401
 *   - Validate;
402
 *   - Submit.
403
 *
334 404
 * @todo This is all terrible. Remove.
335 405
 */
336
function _feeds_form_helper($form, &$form_state, $action) {
406
function _feeds_form_helper(array $form, array &$form_state, $action) {
337 407
  $method = $form['#feeds_form_method'] . $action;
338 408
  $class = get_class($form['#configurable']);
339 409
  $id = $form['#configurable']->id;

Formats disponibles : Unified diff