Conditions | 4 |
Paths | 3 |
Total Lines | 20 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 20 |
Changes | 0 |
1 | <?php |
||
35 | public function getIdByArguments($title, $contentType = '') |
||
36 | { |
||
37 | $nid = new FetchField('node', 'nid'); |
||
38 | $nid->condition('title', "$title%", 'like'); |
||
39 | |||
40 | // Try to recognize node type by its title if content type specified and does not exist. |
||
41 | if ('' !== $contentType && !isset(node_type_get_types()[$contentType])) { |
||
42 | $contentType = (new FetchField('node_type', 'type')) |
||
43 | ->condition('name', $contentType) |
||
44 | ->execute(); |
||
45 | |||
46 | if ('' === $contentType) { |
||
47 | throw new \InvalidArgumentException('Content type with such name does not exist!'); |
||
48 | } |
||
49 | |||
50 | $nid->condition('type', $contentType); |
||
51 | } |
||
52 | |||
53 | return $nid->execute(); |
||
54 | } |
||
55 | } |
||
56 |