Completed
Push — master ( 59c799...149ad0 )
by Will
02:15
created

ElementalGridFieldAddExistingAutocompleter.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * This class is is responsible for adding objects to another object's has_many
4
 * and many_many relation, as defined by the {@link RelationList} passed to the
5
 * {@link GridField} constructor.
6
 *
7
 * Objects can be searched through an input field (partially matching one or
8
 * more fields).
9
 *
10
 * Selecting from the results will add the object to the relation.
11
 *
12
 * Often used alongside {@link GridFieldDeleteAction} for detaching existing
13
 * records from a relationship.
14
 *
15
 * For easier setup, have a look at a sample configuration in
16
 * {@link GridFieldConfig_RelationEditor}.
17
 *
18
 * @package forms
19
 * @subpackage fields-gridfield
20
 */
21
class ElementalGridFieldAddExistingAutocompleter extends GridFieldAddExistingAutocompleter {
22
23
    /**
24
     * If an object ID is set, add the object to the list
25
     *
26
     * @param GridField $gridField
27
     * @param SS_List $dataList
28
     * @return SS_List
29
     */
30
    public function getManipulatedData(GridField $gridField, SS_List $dataList)
31
    {
32
        $objectID = $gridField->State->GridFieldAddRelation(null);
33
34
        if(empty($objectID)) {
35
            return $dataList;
36
        }
37
38
        $object = DataObject::get_by_id($dataList->dataclass(), $objectID);
39
40
        if($object) {
41
            $virtual = new ElementVirtualLinked();
42
            $virtual->LinkedElementID = $object->ID;
0 ignored issues
show
The property LinkedElementID does not exist on object<ElementVirtualLinked>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
43
            $virtual->write();
44
45
            $dataList->add($virtual);
46
        }
47
48
        $gridField->State->GridFieldAddRelation = null;
49
50
        return $dataList;
51
    }
52
}
53